androidandroid-preferencesconfirmationdialog-preference

How to implement a confirmation (yes/no) DialogPreference?


How can I implement a Preference that displays a simple yes/no confirmation dialog?

For an example, see Browser->Setting->Clear Cache.


Solution

  • That is a simple alert dialog, Federico gave you a site where you can look things up.

    Here is a short example of how an alert dialog can be built.

    new AlertDialog.Builder(this)
    .setTitle("Title")
    .setMessage("Do you really want to whatever?")
    .setIcon(android.R.drawable.ic_dialog_alert)
    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
    
        public void onClick(DialogInterface dialog, int whichButton) {
            Toast.makeText(MainActivity.this, "Yaay", Toast.LENGTH_SHORT).show();
        }})
     .setNegativeButton(android.R.string.no, null).show();