Just use a default Preference item rather than a derived
ListPreference.

All you need is to manually handle the click on the preference. I have
exactly the same functionality..

final Preference reset = (Preference)findPreference("reset");
reset.setOnPreferenceClickListener(new
Preference.OnPreferenceClickListener() {

@Override
        public boolean onPreferenceClick(Preference preference)
        {
            AlertDialog.Builder builder = new
AlertDialog.Builder.YourAppNameSettings.this);
            builder.setMessage("This will clear all settings. Are you
sure?");
            builder.setPositiveButton("Yes", dialogClickListener);
            builder.setNegativeButton("No", dialogClickListener);
                                builder.show();
           return false;
        }
             });

Then handle the result from the dialog in the usual way:

    DialogInterface.OnClickListener dialogClickListener = new
DialogInterface.OnClickListener()
    {
        @Override
        public void onClick(DialogInterface dialog, int which)
        {
                switch (which)
                {
                        case DialogInterface.BUTTON_POSITIVE:             //Yes 
button
clicked, reset the settings
                                ResetToDefault();
                                break;
                        case DialogInterface.BUTTON_NEGATIVE:             //No 
button
clicked, do nothing
                                break;
                }
        }
    };



On Apr 16, 9:37 pm, Peter Webb <[email protected]> wrote:
> My app has a "Restore Defaults" function in its Preference Activity. I
> want the user to confirm the selection with a box which says "Are you
> sure," with a OK button and a Cancel button. I built this using a
> ListPreference with two items and while it works it doesn't "look
> right".
>
> Is there some easy way to modify an existing Preference class to do
> this? I just want some text and two buttons. Or does anybody know
> where I can get a suitable preference?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to