4

I want to display a ListPreference Dialog in a non Preference Activity.

Here's my the code that creates the Dialog

// this is my current activity
ListPreference listPreference = new ListPreference(this);   
listPreference.setDialogIcon(R.drawable.auto_download);
listPreference.setTitle(R.string.autoDownloadTitle);
listPreference.setEntries(R.array.autoDownloadEntries);
listPreference.setEntryValues(R.array.autoDownloadValues);
listPreference.setNegativeButtonText(R.string.cancel);
Dialog dialog = listPreference.getDialog();

My problem is that dialog is allways null... What did I miss ?

user1026605
  • 1,633
  • 4
  • 22
  • 58

1 Answers1

1

You cannot do this kind of things, Preference should be in the PreferenceScreen and the activity must extend PreferenceActivity.

I think you want to implement a dialog that show the list of choices like ListPreference do. I recommend to use AlertDialog with list views (based on ArrayAdapter).

Check this for example or AlertDialog.Builder documentation.

Community
  • 1
  • 1
KimKha
  • 4,370
  • 1
  • 37
  • 45