Example usage for android.app AlertDialog setView

List of usage examples for android.app AlertDialog setView

Introduction

In this page you can find the example usage for android.app AlertDialog setView.

Prototype

public void setView(View view) 

Source Link

Document

Set the view to display in that dialog.

Usage

From source file:net.clcworld.thermometer.TakeTemperatureReadingActivity.java

/** Called when the activity is first created. */
@Override//from   ww  w. jav  a2s.c  o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mSelf = this;

    Intent i = new Intent();
    i.setClass(this, LauncherActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent relaunchIntent = PendingIntent.getActivity(this, 0, i, 0);

    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    Intent data = this.getIntent();

    if (data.getBooleanExtra("FROM_ALARM", false)) {
        // Only show the persistant notification if it's from the alarm.
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.app_icon).setTicker(getString(R.string.notification))
                .setContentTitle(getString(R.string.app_name)).setContentText(getString(R.string.notification))
                .setOngoing(true).setOnlyAlertOnce(false).setContentIntent(relaunchIntent)
                .setSound(Settings.System.DEFAULT_NOTIFICATION_URI).setLights(Color.RED, 500, 500);
        mNotificationManager.notify(NOTIFICATION_NUMBER, builder.build());
    }

    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    mFeeling = mPrefs.getString("lastFeeling", STATUS_WELL);
    mHistory = mPrefs.getString(PREFSKEY_HISTORY, "");
    final String id = mPrefs.getString("ID", "");

    setContentView(R.layout.temperature);
    mTemperatureEditText = (EditText) findViewById(R.id.temperature);
    mTemperatureEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                hideKeyboard(v);
            }
        }
    });

    final LinearLayout symptomsList = (LinearLayout) findViewById(R.id.symptoms);
    final CheckBox extremeTiredness = (CheckBox) findViewById(R.id.extremetiredness);
    if (mPrefs.getBoolean(PREFSKEY_SYMPTOMS_EXTREMETIREDNESS, false)) {
        extremeTiredness.setChecked(true);
    }
    final CheckBox musclepain = (CheckBox) findViewById(R.id.musclepain);
    if (mPrefs.getBoolean(PREFSKEY_SYMPTOMS_MUSCLEPAIN, false)) {
        musclepain.setChecked(true);
    }
    final CheckBox headache = (CheckBox) findViewById(R.id.headache);
    if (mPrefs.getBoolean(PREFSKEY_SYMPTOMS_HEADACHE, false)) {
        headache.setChecked(true);
    }
    final CheckBox sorethroat = (CheckBox) findViewById(R.id.sorethroat);
    if (mPrefs.getBoolean(PREFSKEY_SYMPTOMS_SORETHROAT, false)) {
        sorethroat.setChecked(true);
    }
    final CheckBox vomiting = (CheckBox) findViewById(R.id.vomiting);
    if (mPrefs.getBoolean(PREFSKEY_SYMPTOMS_VOMITING, false)) {
        vomiting.setChecked(true);
    }
    final CheckBox diarrhea = (CheckBox) findViewById(R.id.diarrhea);
    if (mPrefs.getBoolean(PREFSKEY_SYMPTOMS_DIARRHEA, false)) {
        diarrhea.setChecked(true);
    }
    final CheckBox rash = (CheckBox) findViewById(R.id.rash);
    if (mPrefs.getBoolean(PREFSKEY_SYMPTOMS_RASH, false)) {
        rash.setChecked(true);
    }
    final CheckBox bleeding = (CheckBox) findViewById(R.id.bleeding);
    if (mPrefs.getBoolean(PREFSKEY_SYMPTOMS_BLEEDING, false)) {
        bleeding.setChecked(true);
    }
    final CheckBox painrelief = (CheckBox) findViewById(R.id.painrelief);
    if (mPrefs.getBoolean(PREFSKEY_SYMPTOMS_PAINRELIEF, false)) {
        painrelief.setChecked(true);
    }

    final Button submitButton = (Button) findViewById(R.id.submit);
    submitButton.setText(R.string.save);
    final String destination = mPrefs.getString("DEST", "");
    if (destination.length() > 0) {
        submitButton.setText(getString(R.string.submit) + destination);
    }
    submitButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            String tempString = mTemperatureEditText.getText().toString();
            try {
                float t = Float.parseFloat(tempString);
                // Come up with better thresholds + use an alert
                // confirmation prompt.
                if ((t < 91) || (t > 120)) {
                    Toast.makeText(mSelf, R.string.retake, Toast.LENGTH_LONG).show();
                    return;
                }

                mTemperatureEditText.setEnabled(false);
                submitButton.setEnabled(false);
                Editor editor = mPrefs.edit();
                editor.putLong("LAST_READING", System.currentTimeMillis());

                ArrayList<String> symptoms = new ArrayList<String>();
                if (mFeeling.equals(STATUS_WELL)) {
                    editor.putBoolean(PREFSKEY_SYMPTOMS_EXTREMETIREDNESS, false);
                    editor.putBoolean(PREFSKEY_SYMPTOMS_MUSCLEPAIN, false);
                    editor.putBoolean(PREFSKEY_SYMPTOMS_HEADACHE, false);
                    editor.putBoolean(PREFSKEY_SYMPTOMS_SORETHROAT, false);
                    editor.putBoolean(PREFSKEY_SYMPTOMS_VOMITING, false);
                    editor.putBoolean(PREFSKEY_SYMPTOMS_DIARRHEA, false);
                    editor.putBoolean(PREFSKEY_SYMPTOMS_RASH, false);
                    editor.putBoolean(PREFSKEY_SYMPTOMS_BLEEDING, false);
                    editor.putBoolean(PREFSKEY_SYMPTOMS_PAINRELIEF, false);
                } else {
                    if (extremeTiredness.isChecked()) {
                        editor.putBoolean(PREFSKEY_SYMPTOMS_EXTREMETIREDNESS, true);
                        symptoms.add(PREFSKEY_SYMPTOMS_EXTREMETIREDNESS);
                    }
                    if (musclepain.isChecked()) {
                        editor.putBoolean(PREFSKEY_SYMPTOMS_MUSCLEPAIN, true);
                        symptoms.add(PREFSKEY_SYMPTOMS_MUSCLEPAIN);
                    }
                    if (headache.isChecked()) {
                        editor.putBoolean(PREFSKEY_SYMPTOMS_HEADACHE, true);
                        symptoms.add(PREFSKEY_SYMPTOMS_HEADACHE);
                    }
                    if (sorethroat.isChecked()) {
                        editor.putBoolean(PREFSKEY_SYMPTOMS_SORETHROAT, true);
                        symptoms.add(PREFSKEY_SYMPTOMS_SORETHROAT);
                    }
                    if (vomiting.isChecked()) {
                        editor.putBoolean(PREFSKEY_SYMPTOMS_VOMITING, true);
                        symptoms.add(PREFSKEY_SYMPTOMS_VOMITING);
                    }
                    if (diarrhea.isChecked()) {
                        editor.putBoolean(PREFSKEY_SYMPTOMS_DIARRHEA, true);
                        symptoms.add(PREFSKEY_SYMPTOMS_DIARRHEA);
                    }
                    if (rash.isChecked()) {
                        editor.putBoolean(PREFSKEY_SYMPTOMS_RASH, true);
                        symptoms.add(PREFSKEY_SYMPTOMS_RASH);
                    }
                    if (bleeding.isChecked()) {
                        editor.putBoolean(PREFSKEY_SYMPTOMS_BLEEDING, true);
                        symptoms.add(PREFSKEY_SYMPTOMS_BLEEDING);
                    }
                    if (painrelief.isChecked()) {
                        editor.putBoolean(PREFSKEY_SYMPTOMS_PAINRELIEF, true);
                        symptoms.add(PREFSKEY_SYMPTOMS_PAINRELIEF);
                    }
                }

                editor.commit();
                mNotificationManager.cancelAll();

                DecimalFormat decFormat = new DecimalFormat("0.0");
                sendData(id, decFormat.format(t), mFeeling, symptoms);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    mFeelingRadioGroup = (RadioGroup) findViewById(R.id.radioGroupFeeling);
    int selectedId = R.id.radioWell;
    if (mFeeling.equals(STATUS_SICK)) {
        selectedId = R.id.radioSick;
        if (destination.length() > 0) {
            symptomsList.setVisibility(View.VISIBLE);
        }
    }
    mFeelingRadioGroup.check(selectedId);
    mFeelingRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (checkedId == R.id.radioSick) {
                mFeeling = STATUS_SICK;
                if (destination.length() > 0) {
                    symptomsList.setVisibility(View.VISIBLE);
                }
            } else {
                mFeeling = STATUS_WELL;
                symptomsList.setVisibility(View.GONE);
            }
            Editor editor = mPrefs.edit();
            editor.putString("lastFeeling", mFeeling);
            editor.commit();
        }
    });

    Button historyButton = (Button) findViewById(R.id.history);
    if (mHistory.length() < 1) {
        historyButton.setVisibility(View.GONE);
    }
    historyButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mSelf);
            alertDialogBuilder.setTitle(R.string.history);
            alertDialogBuilder.setPositiveButton(R.string.ok, null);
            AlertDialog dialog = alertDialogBuilder.create();
            TextView text = new TextView(mSelf);
            text.setTextSize(16);
            text.setPadding(40, 40, 40, 40);
            text.setText(mHistory);
            ScrollView scroll = new ScrollView(mSelf);
            scroll.addView(text);
            dialog.setView(scroll);
            dialog.show();
        }
    });

    Button viewTosButton = (Button) findViewById(R.id.viewtos);
    viewTosButton.setText(R.string.tos_title_local);
    mIsActivated = false;
    if (destination.length() > 0) {
        mIsActivated = true;
        viewTosButton.setText(R.string.tos_title_publichealth);
    }
    viewTosButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent viewTosIntent = new Intent();
            viewTosIntent.setClass(mSelf, TosActivity.class);
            viewTosIntent.putExtra("VIEW_ONLY", true);
            startActivity(viewTosIntent);
        }
    });
}

From source file:net.fabiszewski.ulogger.MainActivity.java

/**
 * Display About dialog/* w  w  w . ja  v  a  2  s .  c  o m*/
 */
private void showAbout() {
    @SuppressLint("InflateParams")
    View view = getLayoutInflater().inflate(R.layout.about, null, false);
    AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
    alertDialog.setTitle(getString(R.string.app_name));
    alertDialog.setView(view);
    alertDialog.setIcon(R.drawable.ic_ulogger_logo_24dp);
    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    alertDialog.show();
    final TextView versionLabel = (TextView) alertDialog.findViewById(R.id.about_version);
    versionLabel.setText(getString(R.string.about_version, BuildConfig.VERSION_NAME));
    final TextView descriptionLabel = (TextView) alertDialog.findViewById(R.id.about_description);
    final TextView description2Label = (TextView) alertDialog.findViewById(R.id.about_description2);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
        descriptionLabel.setText(fromHtmlDepreciated(getString(R.string.about_description)));
        description2Label.setText(fromHtmlDepreciated(getString(R.string.about_description2)));
    } else {
        descriptionLabel.setText(
                Html.fromHtml(getString(R.string.about_description), android.text.Html.FROM_HTML_MODE_LEGACY));
        description2Label.setText(
                Html.fromHtml(getString(R.string.about_description2), android.text.Html.FROM_HTML_MODE_LEGACY));
    }
}

From source file:com.ovrhere.android.careerstack.ui.fragments.dialogs.DistanceDialogFragment.java

@SuppressLint("InflateParams")
@Override/*  ww w  .  ja va2 s  .  c o m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Context ctx = getCompatContext();
    AlertDialog dialog = new AlertDialog.Builder(ctx)
            .setTitle(getResources().getString(R.string.careerstack_dialog_distance_title))
            .setPositiveButton(android.R.string.ok, this).setNegativeButton(android.R.string.cancel, this)
            .create(); //create basic dialog

    //insert custom views
    View content = View.inflate(ctx, R.layout.viewstub_distance_seekbar, null);
    initViews(content); //preload views

    Resources r = getResources();
    content.setPadding(r.getDimensionPixelSize(R.dimen.dialog_margins),
            r.getDimensionPixelSize(R.dimen.dialog_margins), r.getDimensionPixelSize(R.dimen.dialog_margins),
            r.getDimensionPixelSize(R.dimen.dialog_margins));
    dialog.setView(content);
    onValueUpdate(currentDistanceValue);
    return dialog;
}

From source file:net.fabiszewski.ulogger.MainActivity.java

/**
 * Called when the user clicks the track text view
 * @param view View/* ww  w  .ja va2 s .  c o m*/
 */
public void trackSummary(@SuppressWarnings("UnusedParameters") View view) {
    final TrackSummary summary = db.getTrackSummary();
    if (summary == null) {
        showToast(getString(R.string.no_positions));
        return;
    }

    @SuppressLint("InflateParams")
    View summaryView = getLayoutInflater().inflate(R.layout.summary, null, false);
    AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
    alertDialog.setTitle(getString(R.string.track_summary));
    alertDialog.setView(summaryView);
    alertDialog.setIcon(R.drawable.ic_equalizer_white_24dp);
    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    alertDialog.show();

    final TextView summaryDistance = (TextView) alertDialog.findViewById(R.id.summary_distance);
    final TextView summaryDuration = (TextView) alertDialog.findViewById(R.id.summary_duration);
    final TextView summaryPositions = (TextView) alertDialog.findViewById(R.id.summary_positions);
    double distance = (double) summary.getDistance() / 1000;
    String unitName = getString(R.string.unit_kilometer);
    if (pref_units.equals(getString(R.string.pref_units_imperial))) {
        distance *= KM_MILE;
        unitName = getString(R.string.unit_mile);
    }
    final NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(2);
    final String distanceString = nf.format(distance);
    summaryDistance.setText(getString(R.string.summary_distance, distanceString, unitName));
    final long h = summary.getDuration() / 3600;
    final long m = summary.getDuration() % 3600 / 60;
    summaryDuration.setText(getString(R.string.summary_duration, h, m));
    int positionsCount = (int) summary.getPositionsCount();
    if (needsPluralFewHack(positionsCount)) {
        summaryPositions.setText(getResources().getString(R.string.summary_positions_few, positionsCount));
    } else {
        summaryPositions.setText(
                getResources().getQuantityString(R.plurals.summary_positions, positionsCount, positionsCount));
    }
}

From source file:com.aniruddhc.acemusic.player.FoldersFragment.FilesFoldersFragment.java

/**
 * Displays a "Rename" dialog and renames the specified file/folder.
 *
 * @param path The path of the folder/file that needs to be renamed.
 *//*from  w  ww. j  a v a 2  s  .c  om*/
public void rename(String path) {

    final File renameFile = new File(path);
    final AlertDialog renameAlertDialog = new AlertDialog.Builder(getActivity()).create();
    final EditText fileEditText = new EditText(getActivity());

    fileEditText.setHint(R.string.file_name);
    fileEditText.setSingleLine(true);
    fileEditText.setText(renameFile.getName());

    renameAlertDialog.setView(fileEditText);
    renameAlertDialog.setTitle(R.string.rename);
    renameAlertDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
            mContext.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    renameAlertDialog.dismiss();
                }

            });

    renameAlertDialog.setButton(DialogInterface.BUTTON_POSITIVE,
            mContext.getResources().getString(R.string.rename), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    //Check if the new file name is empty.
                    if (fileEditText.getText().toString().isEmpty()) {
                        Toast.makeText(getActivity(), R.string.enter_a_name_for_folder, Toast.LENGTH_LONG)
                                .show();
                    } else {

                        File newNameFile = null;
                        try {
                            newNameFile = new File(renameFile.getParentFile().getCanonicalPath() + "/"
                                    + fileEditText.getText().toString());
                        } catch (IOException e) {
                            e.printStackTrace();
                            Toast.makeText(getActivity(), R.string.folder_could_not_be_renamed,
                                    Toast.LENGTH_LONG).show();
                            return;
                        }

                        try {
                            if (renameFile.isDirectory())
                                FileUtils.moveDirectory(renameFile, newNameFile);
                            else
                                FileUtils.moveFile(renameFile, newNameFile);

                        } catch (IOException e) {
                            e.printStackTrace();
                            Toast.makeText(getActivity(), R.string.folder_could_not_be_renamed,
                                    Toast.LENGTH_LONG).show();
                            return;
                        }

                        Toast.makeText(getActivity(), R.string.folder_renamed, Toast.LENGTH_SHORT).show();
                        renameAlertDialog.dismiss();
                        refreshListView();

                    }

                }

            });

    renameAlertDialog.show();

}

From source file:smart.services.adapter.ManageCarsAdapter.java

private void deleteDialog(final int position) {
    final TextView input = new TextView(context);
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
    alertDialogBuilder.setTitle("Delete");

    alertDialogBuilder.setCancelable(false).setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        @SuppressLint("DefaultLocale")
        public void onClick(DialogInterface dialog, int id) {
            DeleteCar deleteCar = new DeleteCar(position);
            deleteCar.execute();//from  w w  w . ja v  a  2  s.c  o  m
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

    // create alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    input.setText("Are You sure You want to delete this record ?");
    input.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    input.setTextSize(20);
    input.setLayoutParams(lp);
    alertDialog.setView(input);
    alertDialog.show();
}

From source file:in.animeshpathak.nextbus.NextBusMain.java

/**
 * Creates the Application Info dialog with clickable links.
 * //from w  w  w.  j  av  a  2  s  .  c  om
 * @throws UnsupportedEncodingException
 * @throws IOException
 */
private void showVersionInfoDialog() throws UnsupportedEncodingException, IOException {
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle(getString(R.string.app_name) + " " + getString(R.string.version_name));

    AssetManager assetManager = getResources().getAssets();
    String versionInfoFile = getString(R.string.versioninfo_asset);
    InputStreamReader reader = new InputStreamReader(assetManager.open(versionInfoFile), "UTF-8");
    BufferedReader br = new BufferedReader(reader);
    StringBuffer sbuf = new StringBuffer();
    String line;
    while ((line = br.readLine()) != null) {
        sbuf.append(line);
        sbuf.append("\r\n");
    }

    final ScrollView scroll = new ScrollView(this);
    final TextView message = new TextView(this);
    final SpannableString sWlinks = new SpannableString(sbuf.toString());
    Linkify.addLinks(sWlinks, Linkify.WEB_URLS);
    message.setText(sWlinks);
    message.setMovementMethod(LinkMovementMethod.getInstance());
    message.setPadding(15, 15, 15, 15);
    scroll.addView(message);
    alertDialog.setView(scroll);
    alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Ok", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // nothing to do, just dismiss dialog
        }
    });
    alertDialog.show();
}

From source file:com.github.mobile.ui.repo.RepositoryListFragment.java

@Override
public boolean onListItemLongClick(ListView list, View v, int position, long itemId) {
    if (!isUsable())
        return false;

    final Repository repo = (Repository) list.getItemAtPosition(position);
    if (repo == null)
        return false;

    final AlertDialog dialog = LightAlertDialog.create(getActivity());
    dialog.setCanceledOnTouchOutside(true);

    dialog.setTitle(repo.generateId());//from  w  w w.  j  a  v a  2 s  .  co m

    View view = getActivity().getLayoutInflater().inflate(layout.repo_dialog, null);
    ViewFinder finder = new ViewFinder(view);

    final User owner = repo.getOwner();
    avatars.bind(finder.imageView(id.iv_owner_avatar), owner);
    finder.setText(id.tv_owner_name, getString(string.navigate_to_user, owner.getLogin()));
    finder.onClick(id.ll_owner_area, new OnClickListener() {

        public void onClick(View v) {
            dialog.dismiss();

            viewUser(owner);
        }
    });

    if ((recentRepos != null) && (recentRepos.contains(repo))) {
        finder.find(id.divider).setVisibility(View.VISIBLE);
        finder.find(id.ll_recent_repo_area).setVisibility(View.VISIBLE);
        finder.onClick(id.ll_recent_repo_area, new OnClickListener() {

            public void onClick(View v) {
                dialog.dismiss();

                recentRepos.remove(repo);
                refresh();
            }
        });
    }

    dialog.setView(view);
    dialog.show();

    return true;
}

From source file:com.janela.mobile.ui.repo.RepositoryListFragment.java

@Override
public boolean onListItemLongClick(ListView list, View v, int position, long itemId) {
    if (!isUsable())
        return false;

    final Repository repo = (Repository) list.getItemAtPosition(position);
    if (repo == null)
        return false;

    final AlertDialog dialog = LightAlertDialog.create(getActivity());
    dialog.setCanceledOnTouchOutside(true);

    dialog.setTitle(repo.generateId());//from   w ww  .ja  va  2s .c  om

    View view = getActivity().getLayoutInflater().inflate(R.layout.repo_dialog, null);
    ViewFinder finder = new ViewFinder(view);

    final User owner = repo.getOwner();
    avatars.bind(finder.imageView(R.id.iv_owner_avatar), owner);
    finder.setText(R.id.tv_owner_name, getString(R.string.navigate_to_user, owner.getLogin()));
    finder.onClick(R.id.ll_owner_area, new OnClickListener() {

        public void onClick(View v) {
            dialog.dismiss();

            viewUser(owner);
        }
    });

    if ((recentRepos != null) && (recentRepos.contains(repo))) {
        finder.find(R.id.divider).setVisibility(View.VISIBLE);
        finder.find(R.id.ll_recent_repo_area).setVisibility(View.VISIBLE);
        finder.onClick(R.id.ll_recent_repo_area, new OnClickListener() {

            public void onClick(View v) {
                dialog.dismiss();

                recentRepos.remove(repo);
                refresh();
            }
        });
    }

    dialog.setView(view);
    dialog.show();

    return true;
}

From source file:com.github.pockethub.ui.repo.RepositoryListFragment.java

@Override
public boolean onListItemLongClick(ListView list, View v, int position, long itemId) {
    if (!isUsable())
        return false;

    final Repo repo = (Repo) list.getItemAtPosition(position);
    if (repo == null)
        return false;

    final AlertDialog dialog = LightAlertDialog.create(getActivity());
    dialog.setCanceledOnTouchOutside(true);

    dialog.setTitle(InfoUtils.createRepoId(repo));

    View view = getActivity().getLayoutInflater().inflate(R.layout.repo_dialog, null);
    ViewFinder finder = new ViewFinder(view);

    final User owner = repo.owner;
    avatars.bind(finder.imageView(R.id.iv_owner_avatar), owner);
    finder.setText(R.id.tv_owner_name, getString(R.string.navigate_to_user, owner.login));
    finder.onClick(R.id.ll_owner_area, new OnClickListener() {

        public void onClick(View v) {
            dialog.dismiss();/*from  w ww.  j av a 2s. c  o m*/

            viewUser(owner);
        }
    });

    if ((recentRepos != null) && (recentRepos.contains(repo))) {
        finder.find(R.id.divider).setVisibility(View.VISIBLE);
        finder.find(R.id.ll_recent_repo_area).setVisibility(View.VISIBLE);
        finder.onClick(R.id.ll_recent_repo_area, new OnClickListener() {

            public void onClick(View v) {
                dialog.dismiss();

                recentRepos.remove(repo);
                refresh();
            }
        });
    }

    dialog.setView(view);
    dialog.show();

    return true;
}