Example usage for android.view View inflate

List of usage examples for android.view View inflate

Introduction

In this page you can find the example usage for android.view View inflate.

Prototype

public static View inflate(Context context, @LayoutRes int resource, ViewGroup root) 

Source Link

Document

Inflate a view from an XML resource.

Usage

From source file:com.feedhenry.sync.activities.ListOfItemsActivity.java

private void showPopup(final ShoppingItem item) {
    final View customView = View.inflate(getApplicationContext(), R.layout.form_item_dialog, null);
    final EditText name = (EditText) customView.findViewById(R.id.name);
    name.setText(item.getName());//from   w ww  .j a va  2 s.c  o m

    new MaterialDialog.Builder(this)
            .title((item.getId() == null) ? getString(R.string.new_item)
                    : getString(R.string.edit_item) + ": " + item.getName())
            .customView(customView, false).positiveText(R.string.save)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    item.setName(name.getText().toString());
                    saveItem(item);
                }
            }).negativeText(R.string.cancel).show();
}

From source file:org.liberty.android.fantastischmemopro.downloader.DownloaderFE.java

@Override
protected void fetchDatabase(final DownloadItem di) {
    View alertView = View.inflate(this, R.layout.link_alert, null);
    TextView textView = (TextView) alertView.findViewById(R.id.link_alert_message);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    textView.setText(//from  w ww.j  a  v a  2 s.c  om
            Html.fromHtml(getString(R.string.downloader_download_alert_message) + di.getDescription()));

    new AlertDialog.Builder(this).setView(alertView)
            .setTitle(getString(R.string.downloader_download_alert) + di.getTitle())
            .setPositiveButton(getString(R.string.yes_text), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface arg0, int arg1) {
                    mProgressDialog = ProgressDialog.show(DownloaderFE.this,
                            getString(R.string.loading_please_wait), getString(R.string.loading_downloading));
                    new Thread() {
                        public void run() {
                            try {
                                downloadDatabase(di);
                                mHandler.post(new Runnable() {
                                    public void run() {
                                        mProgressDialog.dismiss();
                                        String dbpath = Environment.getExternalStorageDirectory()
                                                .getAbsolutePath() + getString(R.string.default_dir);
                                        new AlertDialog.Builder(DownloaderFE.this)
                                                .setTitle(R.string.downloader_download_success)
                                                .setMessage(
                                                        getString(R.string.downloader_download_success_message)
                                                                + dbpath + di.getTitle() + ".db")
                                                .setPositiveButton(R.string.ok_text, null).create().show();
                                    }
                                });

                            } catch (final Exception e) {
                                Log.e(TAG, "Error downloading", e);
                                mHandler.post(new Runnable() {
                                    public void run() {
                                        mProgressDialog.dismiss();
                                        new AlertDialog.Builder(DownloaderFE.this)
                                                .setTitle(R.string.downloader_download_fail)
                                                .setMessage(getString(R.string.downloader_download_fail_message)
                                                        + " " + e.toString())
                                                .setPositiveButton(R.string.ok_text, null).create().show();
                                    }
                                });
                            }
                        }
                    }.start();
                }
            }).setNegativeButton(getString(R.string.no_text), null).show();
}

From source file:com.nearnotes.NoteEdit.java

@Override
public void onStart() {
    super.onStart();
    mTitleText = (EditText) getActivity().findViewById(R.id.title_edit);

    mCallback.setActionItems(NOTE_EDIT);
    if (mRowId == null) {
        Bundle extras = getArguments();/*from  w w w .jav  a2s .  co m*/
        mRowId = extras.containsKey(NotesDbAdapter.KEY_ROWID) ? extras.getLong(NotesDbAdapter.KEY_ROWID) : null;
    }

    getActivity().setTitle(R.string.edit_note);

    Bundle bundle = getArguments();
    mLongitude = bundle.getDouble("longitude");
    mLatitude = bundle.getDouble("latitude");

    mTitleText = (EditText) getActivity().findViewById(R.id.title_edit);
    mBodyText = (EditText) getView().findViewById(R.id.body);

    mTblAddLayout = (TableLayout) getActivity().findViewById(R.id.checkbody);
    mTblAddLayout.setPadding(0, 0, 0, 0);

    acAdapter = new PlacesAutoCompleteAdapter(getActivity(), R.layout.list_item);

    mCheckBox = (CheckBox) getActivity().findViewById(R.id.checkbox_on_top);
    mCheckBox.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (((CheckBox) v).isChecked() && mRowId != null) {
                mDbHelper.updateSetting(mRowId);
            } else if (mRowId != null) {
                mDbHelper.removeSetting();
            }
        }
    });

    autoCompView = (DelayAutoCompleteTextView) getView().findViewById(R.id.autoCompleteTextView1);
    autoCompView.setAdapter(acAdapter);
    //int height = autoCompView.getDropDownHeight();
    //autoCompView.setDropDownHeight(height + 20);

    autoCompView.setOnItemClickListener(this);
    autoCompView.setLoadingIndicator((ProgressBar) getView().findViewById(R.id.progressAPI),
            (ImageView) getView().findViewById(R.id.location_icon));

    autoCompView.setCompletionHint("");
    if (mRowId != null) {
        autoCompView.setTextColor(getResources().getColor(R.color.deepgreen));
    } else {
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
        boolean checklistPref = sharedPref.getBoolean("pref_key_note_checklist", false);
        if (checklistPref) {
            mChecklist = true;
        }
    }

    mBodyText.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {
            //This listener is added to make sure the globalLayout has been displayed
            // before accessing getLayout().getLineEnd()
            ViewTreeObserver obs = mBodyText.getViewTreeObserver();
            obs.removeGlobalOnLayoutListener(this);

            if (!mChecklist) {
                return;
            }
            mBodyText.addTextChangedListener(bodyTextWatcher);

            // Run the code below just once on startup to populate the global listArray mRealRow
            String tempBoxes = mBodyText.getText().toString();
            if (mBodyText.getLayout() != null) {
                mRealRow = populateBoxes(tempBoxes);

                int row = 0;
                for (NoteRow line : mRealRow) {
                    switch (line.getType()) {
                    case 0:
                        TableRow inflate = (TableRow) View.inflate(getActivity(), R.layout.table_row_invisible,
                                null);
                        mTblAddLayout.addView(inflate);
                        break;
                    case 1:
                        TableRow checkRow = (TableRow) View.inflate(getActivity(), R.layout.table_row, null);
                        CheckBox temp = (CheckBox) checkRow.getChildAt(0);
                        temp.setTag(Integer.valueOf(row));
                        mTblAddLayout.addView(checkRow);
                        temp.setOnClickListener(checkBoxListener);
                        break;
                    case 2:
                        TableRow checkRow1 = (TableRow) View.inflate(getActivity(), R.layout.table_row, null);
                        CheckBox temp1 = (CheckBox) checkRow1.getChildAt(0);
                        temp1.setTag(Integer.valueOf(row));
                        temp1.setChecked(true);
                        mTblAddLayout.addView(checkRow1);
                        temp1.setOnClickListener(checkBoxListener);
                        break;
                    }

                    for (int k = 1; line.getSize() > k; k++) {
                        TableRow inflate = (TableRow) View.inflate(getActivity(), R.layout.table_row_invisible,
                                null);
                        mTblAddLayout.addView(inflate);
                    }
                    row++;
                }
            }
        }
    });
}

From source file:org.cyanogenmod.theme.chooser.AudiblePreviewFragment.java

private void addAudibleToLayout(int type, MediaPlayer mp) {
    View view = View.inflate(getActivity(), R.layout.audible_preview_item, null);
    TextView tv = (TextView) view.findViewById(R.id.audible_name);
    switch (type) {
    case RingtoneManager.TYPE_ALARM:
        tv.setText(R.string.alarm_label);
        break;/*  w w  w . ja  va2  s.c  o  m*/
    case RingtoneManager.TYPE_NOTIFICATION:
        tv.setText(R.string.notification_label);
        break;
    case RingtoneManager.TYPE_RINGTONE:
        tv.setText(R.string.ringtone_label);
        break;
    }
    ImageView iv = (ImageView) view.findViewById(R.id.btn_play_pause);
    iv.setTag(mp);
    iv.setOnClickListener(mPlayPauseClickListener);
    mContent.addView(view, ITEM_LAYOUT_PARAMS);
}

From source file:org.liberty.android.fantastischmemo.downloader.DownloaderSS.java

protected void fetchDatabase(final DownloadItem di) {
    View alertView = View.inflate(this, R.layout.link_alert, null);
    TextView textView = (TextView) alertView.findViewById(R.id.link_alert_message);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    textView.setText(/*from ww  w . j  a v a 2 s. c  o m*/
            Html.fromHtml(getString(R.string.downloader_download_alert_message) + di.getDescription()));

    new AlertDialog.Builder(this).setView(alertView)
            .setTitle(getString(R.string.downloader_download_alert) + di.getTitle())
            .setPositiveButton(getString(R.string.yes_text), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface arg0, int arg1) {
                    mProgressDialog = ProgressDialog.show(DownloaderSS.this,
                            getString(R.string.loading_please_wait), getString(R.string.loading_downloading));
                    new Thread() {
                        public void run() {
                            try {
                                downloadDatabase(di);
                                mHandler.post(new Runnable() {
                                    public void run() {
                                        mProgressDialog.dismiss();
                                        String dbpath = AMEnv.DEFAULT_ROOT_PATH;
                                        new AlertDialog.Builder(DownloaderSS.this)
                                                .setTitle(R.string.downloader_download_success)
                                                .setMessage(
                                                        getString(R.string.downloader_download_success_message)
                                                                + dbpath + di.getTitle() + ".db")
                                                .setPositiveButton(R.string.ok_text, null).create().show();
                                    }
                                });

                            } catch (final Exception e) {
                                Log.e(TAG, "Error downloading", e);
                                mHandler.post(new Runnable() {
                                    public void run() {
                                        mProgressDialog.dismiss();
                                        new AlertDialog.Builder(DownloaderSS.this)
                                                .setTitle(R.string.downloader_download_fail)
                                                .setMessage(getString(R.string.downloader_download_fail_message)
                                                        + " " + e.toString())
                                                .setPositiveButton(R.string.ok_text, null).create().show();
                                    }
                                });
                            }
                        }
                    }.start();
                }
            }).setNegativeButton(getString(R.string.no_text), null).show();
}

From source file:com.bt.download.android.gui.adapters.TransferListAdapter.java

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
        ViewGroup parent) {/*from  ww  w .  j a v a 2s  .co m*/

    TransferItem item = getChildItem(groupPosition, childPosition);

    if (convertView == null) {
        convertView = View.inflate(context.get(), R.layout.view_transfer_item_list_item, null);

        convertView.setOnClickListener(viewOnClickListener);
        convertView.setOnLongClickListener(viewOnLongClickListener);
    }

    try {

        initTouchFeedback(convertView, item);

        populateChildView(convertView, item);

    } catch (Throwable e) {
        Log.e(TAG, "Fatal error getting view: " + e.getMessage());
    }

    return convertView;
}

From source file:cs.umass.edu.prepare.view.activities.CalendarActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_calendar);

    // on first run, create dummy data: // TODO : get rid of this when deploying
    SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this);
    boolean firstRun = p.getBoolean("PREFERENCE_FIRST_RUN", true);
    if (firstRun) {
        Log.i("PrEPare", "Initial run... Creating dummy data...");
        Utils.setDummyAdherenceData(this);
        p.edit().putBoolean("PREFERENCE_FIRST_RUN", false).apply();
    }/* w w  w.j  a  v a2 s  .  com*/
    if (preferences == null) {
        preferences = DataIO.getInstance(this);
        preferences.addOnDataChangedListener(
                () -> CalendarActivity.this.runOnUiThread(CalendarActivity.this::refresh));
    }
    loadData();

    Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(myToolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowCustomEnabled(true);
    }

    final View v = View.inflate(this, R.layout.menu_item_today, null);

    TextView txtDate = (TextView) v.findViewById(R.id.txt_today);
    txtDate.setText(String.valueOf(today.get(Calendar.DATE)));

    v.setOnClickListener(view -> {
        finish();
        startActivity(getIntent()); // refresh activity
    });

    getSupportActionBar().setCustomView(v);

    adapter = new CalendarAdapter(this, month, selectedDate);
    GridView gridview = (GridView) findViewById(R.id.gridview);
    gridview.setAdapter(adapter);

    handler = new Handler();
    handler.post(calendarUpdater);

    GridView headers = (GridView) findViewById(R.id.gvHeaders);

    ArrayAdapter<String> headersAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,
            new String[] { "S", "M", "T", "W", "T", "F", "S" });
    headers.setAdapter(headersAdapter);

    TextView title = (TextView) findViewById(R.id.title);
    title.setText(android.text.format.DateFormat.format("MMMM yyyy", month));
    final TextView previous = (TextView) findViewById(R.id.previous);
    previous.setOnClickListener(v13 -> previousMonth());

    TextView next = (TextView) findViewById(R.id.next);
    next.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v1) {
            CalendarActivity.this.nextMonth();
        }
    });

    detailsView = findViewById(R.id.details);

    gridview.setOnItemClickListener((parent, v12, position, id) -> {
        TextView date = (TextView) v12.findViewById(R.id.date);
        if (date != null && !date.getText().equals("")) {
            if (date.getText().toString().equals(String.valueOf(selectedDate.get(Calendar.DATE)))) {
                displayDetailsView = !displayDetailsView;
            } else {
                displayDetailsView = true;
            }
            selectedDate.set(Calendar.MONTH, month.get(Calendar.MONTH));
            selectedDate.set(Calendar.YEAR, month.get(Calendar.YEAR));
            selectedDate.set(Calendar.DATE, Integer.valueOf(date.getText().toString()));
            refresh();
        }
    });

    motionEventListener.setOnSwipeListener(gridview, direction -> {
        if (direction == CustomMotionEventListener.OnSwipeListener.Direction.LEFT) {
            nextMonth();
        } else if (direction == CustomMotionEventListener.OnSwipeListener.Direction.RIGHT) {
            previousMonth();
        }
    });

    //      motionEventListener.setOnSwipeListener(detailsView, onDetailsSwiped);
    //      motionEventListener.setOnSwipeListener(this, onDetailsSwiped);

    if (addressMapping == null) { // TODO
        Intent selectDeviceIntent = new Intent(this, SelectDeviceActivity.class);
        startActivity(selectDeviceIntent);
    }

    new CheckForUpdatesTask(this).execute(true);

    Intent wearableServiceIntent = new Intent(this, WearableService.class);
    wearableServiceIntent.setAction(Constants.ACTION.START_SERVICE);
    startService(wearableServiceIntent);

    Intent dataServiceIntent = new Intent(this, DataService.class);
    dataServiceIntent.setAction(Constants.ACTION.START_SERVICE);
    startService(dataServiceIntent);
}

From source file:de.baumann.hhsmoodle.activities.Activity_count.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    PreferenceManager.setDefaultValues(this, R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    toDo_title = sharedPref.getString("count_title", "");
    String count_title = sharedPref.getString("count_content", "");
    toDo_icon = sharedPref.getString("count_icon", "");
    toDo_create = sharedPref.getString("count_create", "");
    String todo_attachment = sharedPref.getString("count_attachment", "");
    if (!sharedPref.getString("count_seqno", "").isEmpty()) {
        toDo_seqno = Integer.parseInt(sharedPref.getString("count_seqno", ""));
    }//from w ww  .ja v a 2s . c om

    setContentView(R.layout.activity_count);
    setTitle(toDo_title);

    final EditText etNewItem = (EditText) findViewById(R.id.etNewItem);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            String itemText = etNewItem.getText().toString();

            if (itemText.isEmpty()) {
                Snackbar.make(lvItems, R.string.todo_enter, Snackbar.LENGTH_LONG).show();
            } else {
                itemsTitle.add(0, itemText);
                itemsCount.add(0, "0");
                etNewItem.setText("");
                writeItemsTitle();
                writeItemsCount();
                lvItems.post(new Runnable() {
                    public void run() {
                        lvItems.setSelection(lvItems.getCount() - 1);
                    }
                });
                adapter.notifyDataSetChanged();
            }
        }
    });

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    helper_main.onStart(Activity_count.this);

    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    try {
        FileOutputStream fOut = new FileOutputStream(newFileTitle());
        OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
        myOutWriter.append(count_title);
        myOutWriter.close();

        fOut.flush();
        fOut.close();
    } catch (IOException e) {
        Log.e("Exception", "File write failed: " + e.toString());
    }

    try {
        FileOutputStream fOut = new FileOutputStream(newFileCount());
        OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
        myOutWriter.append(todo_attachment);
        myOutWriter.close();

        fOut.flush();
        fOut.close();
    } catch (IOException e) {
        Log.e("Exception", "File write failed: " + e.toString());
    }

    lvItems = (ListView) findViewById(R.id.lvItems);
    itemsTitle = new ArrayList<>();
    readItemsTitle();
    readItemsCount();

    adapter = new CustomListAdapter(Activity_count.this, itemsTitle, itemsCount) {
        @NonNull
        @Override
        public View getView(final int position, View convertView, @NonNull ViewGroup parent) {

            View v = super.getView(position, convertView, parent);
            ImageButton ib_plus = (ImageButton) v.findViewById(R.id.but_plus);
            ImageButton ib_minus = (ImageButton) v.findViewById(R.id.but_minus);
            TextView tv = (TextView) v.findViewById(R.id.count_count);

            int count = Integer.parseInt(itemsCount.get(position));

            if (count < 0) {
                tv.setTextColor(ContextCompat.getColor(Activity_count.this, R.color.color_red));
            } else if (count > 0) {
                tv.setTextColor(ContextCompat.getColor(Activity_count.this, R.color.color_green));
            } else if (count == 0) {
                tv.setTextColor(ContextCompat.getColor(Activity_count.this, R.color.color_grey));
            }

            ib_plus.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    int a = Integer.parseInt(itemsCount.get(position)) + 1;
                    String plus = String.valueOf(a);

                    itemsCount.remove(position);
                    itemsCount.add(position, plus);
                    // Refresh the adapter
                    adapter.notifyDataSetChanged();
                    // Return true consumes the long click event (marks it handled)
                    writeItemsTitle();
                    writeItemsCount();

                }
            });

            ib_minus.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    int a = Integer.parseInt(itemsCount.get(position)) - 1;
                    String minus = String.valueOf(a);

                    itemsCount.remove(position);
                    itemsCount.add(position, minus);
                    // Refresh the adapter
                    adapter.notifyDataSetChanged();
                    // Return true consumes the long click event (marks it handled)
                    writeItemsTitle();
                    writeItemsCount();
                }
            });

            return v;
        }
    };

    lvItems.setAdapter(adapter);

    lvItems.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(android.widget.AdapterView<?> parent, View view, final int position, long id) {

            final String title = itemsTitle.get(position);
            final String count = itemsCount.get(position);

            AlertDialog.Builder builder = new AlertDialog.Builder(Activity_count.this);
            View dialogView = View.inflate(Activity_count.this, R.layout.dialog_edit_text_singleline_count,
                    null);

            final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
            edit_title.setText(title);

            builder.setView(dialogView);
            builder.setTitle(R.string.number_edit_entry);
            builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {

                    String inputTag = edit_title.getText().toString().trim();
                    // Remove the item within array at position
                    itemsTitle.remove(position);
                    itemsCount.remove(position);

                    itemsTitle.add(position, inputTag);
                    itemsCount.add(position, count);

                    // Refresh the adapter
                    adapter.notifyDataSetChanged();
                    // Return true consumes the long click event (marks it handled)
                    writeItemsTitle();
                    writeItemsCount();
                }
            });
            builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });

            final AlertDialog dialog2 = builder.create();
            // Display the custom alert dialog on interface
            dialog2.show();
            helper_main.showKeyboard(Activity_count.this, edit_title);
        }
    });

    lvItems.setOnItemLongClickListener(new android.widget.AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(android.widget.AdapterView<?> parent, View view, final int position,
                long id) {

            final String title = itemsTitle.get(position);
            final String count = itemsCount.get(position);

            // Remove the item within array at position
            itemsTitle.remove(position);
            itemsCount.remove(position);
            // Refresh the adapter
            adapter.notifyDataSetChanged();
            // Return true consumes the long click event (marks it handled)
            writeItemsTitle();
            writeItemsCount();

            Snackbar snackbar = Snackbar.make(lvItems, R.string.todo_removed, Snackbar.LENGTH_LONG)
                    .setAction(R.string.todo_removed_back, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            itemsTitle.add(position, title);
                            itemsCount.add(position, count);
                            // Refresh the adapter
                            adapter.notifyDataSetChanged();
                            // Return true consumes the long click event (marks it handled)
                            writeItemsTitle();
                            writeItemsCount();
                        }
                    });
            snackbar.show();

            return true;
        }
    });
}

From source file:me.acristoffers.tracker.activities.PackageListActivity.java

@SuppressLint("InflateParams")
private void about() {
    final View about = View.inflate(this, R.layout.about, null);

    final PackageManager manager = getPackageManager();
    final String packageName = getPackageName();
    int versionCode = 0;
    String versionName = "";

    try {//from  www  . j a  v  a  2 s  . c  om
        final PackageInfo info = manager.getPackageInfo(packageName, 0);
        versionCode = info.versionCode;
        versionName = info.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    final TextView version = (TextView) about.findViewById(R.id.version);
    if (version != null) {
        final String versionText = getString(R.string.version, versionName, versionCode);
        version.setText(versionText);
    }

    final TextView issues = (TextView) about.findViewById(R.id.issues);
    if (issues != null) {
        issues.setMovementMethod(LinkMovementMethod.getInstance());
    }

    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.app_name);
    builder.setView(about);
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
        }
    });
    builder.setNeutralButton(R.string.rate_now, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            final String packageName = getPackageName();
            final Uri uri = Uri.parse("market://details?id=" + packageName);
            startActivity(new Intent(Intent.ACTION_VIEW, uri));
            dialogInterface.dismiss();
        }
    });

    final AlertDialog aboutDialog = builder.create();
    aboutDialog.show();
}

From source file:net.wespot.pim.view.InqCommunicateFragment.java

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    rootView = inflater.inflate(R.layout.fragment_section_communicate, container, false);

    message = (EditText) rootView.findViewById(R.id.communication_enter_message);
    send = (ImageButton) rootView.findViewById(R.id.communication_enter_message_button);

    listViewMessages = (BlockingListView) rootView.findViewById(R.id.list_messages);

    final View more_messages_button = View.inflate(mContext, R.layout.entry_more_messages_button, null);

    final Button a = (Button) more_messages_button.findViewById(R.id.message_button);

    a.setOnClickListener(new View.OnClickListener() {
        @Override/* ww w .java2s .co  m*/
        public void onClick(View v) {
            from_timestamp_message = to_timestamp_message;

            Date date = new Date(from_timestamp_message);
            Format format = new SimpleDateFormat("HH:mm:ss dd-MMM-y");

            Log.e(TAG, "From: " + format.format(date));

            if (number_remain_messages >= 20) {
                do {

                    to_timestamp_message = (System.currentTimeMillis() / 1000 - (limit * 60 * 60)) * 1000;

                    date = new Date(to_timestamp_message);

                    messageLocalObjectList = DaoConfiguration.getInstance().getMessageLocalObject()
                            .queryBuilder()
                            .where(MessageLocalObjectDao.Properties.RunId
                                    .eq(INQ.inquiry.getCurrentInquiry().getRunId()),
                                    MessageLocalObjectDao.Properties.Time.gt(to_timestamp_message),
                                    MessageLocalObjectDao.Properties.Time.lt(from_timestamp_message))
                            .orderDesc(MessageLocalObjectDao.Properties.Time).list();

                    Log.e(TAG, "To: " + format.format(date));
                    Log.e(TAG, "Num. messages: " + messageLocalObjectList.size());

                    limit += 36;

                } while (messageLocalObjectList.size() < 20);
            } else {
                messageLocalObjectList = DaoConfiguration.getInstance().getMessageLocalObject().queryBuilder()
                        .where(MessageLocalObjectDao.Properties.RunId
                                .eq(INQ.inquiry.getCurrentInquiry().getRunId()),
                                MessageLocalObjectDao.Properties.Time.lt(from_timestamp_message))
                        .orderDesc(MessageLocalObjectDao.Properties.Time).list();
                listViewMessages.removeHeaderView(more_messages_button);
            }

            // Hide more messages button to avoid a infinite loop if there are no more messages to show
            Toast.makeText(mContext, messageLocalObjectList.size() + " messages loaded", LENGTH_SHORT).show();
            number_remain_messages -= messageLocalObjectList.size();
            if (number_remain_messages == 0) {
                listViewMessages.removeHeaderView(more_messages_button);
            }

            Log.e(TAG, "remain messages: " + number_remain_messages);

            for (MessageLocalObject messageLocalObject : messageLocalObjectList) {
                messages.add(0, messageLocalObject);
            }

            int firstVisPos = listViewMessages.getFirstVisiblePosition();
            View firstVisView = listViewMessages.getChildAt(0);
            int top = firstVisView != null ? firstVisView.getTop() : 0;

            // Block children layout for now
            listViewMessages.setBlockLayoutChildren(true);

            // Number of items added before the first visible item
            int itemsAddedBeforeFirstVisible = messageLocalObjectList.size();

            // Change the cursor, or call notifyDataSetChanged() if not using a Cursor
            chatAdapter.notifyDataSetChanged();

            // Let ListView start laying out children again
            listViewMessages.setBlockLayoutChildren(false);

            // Call setSelectionFromTop to change the ListView position
            listViewMessages.setSelectionFromTop(firstVisPos + itemsAddedBeforeFirstVisible, top);
        }
    });

    if (number_messages > 5 && number_remain_messages != 0) {
        listViewMessages.addHeaderView(more_messages_button);
    }

    listViewMessages.setAdapter(chatAdapter);

    send.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (!message.getText().toString().equals("")) {
                MessageLocalObject messageLocalObject = new MessageLocalObject();
                messageLocalObject.setBody(message.getText().toString());
                messageLocalObject.setAuthor(INQ.accounts.getLoggedInAccount().getFullId());
                messageLocalObject.setTime(INQ.time.getServerTime());
                messageLocalObject.setRunId(INQ.inquiry.getCurrentInquiry().getRunId());
                messageLocalObject.setSynced(false);
                messageLocalObject.setSubject("");

                DaoConfiguration.getInstance().getMessageLocalObject().insertOrReplace(messageLocalObject);
                INQ.messages.postMessagesToServer();

                messages.add(messageLocalObject);
                messages_views.put(messageLocalObject, null);

                message.setText("");
                chatAdapter.notifyDataSetChanged();
            }
        }
    });
    return rootView;
}