user1026605
user1026605

Reputation: 1430

How to create a ListPreference dialog to display in a non preference activity

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 ?

Upvotes: 4

Views: 1379

Answers (1)

KimKha
KimKha

Reputation: 4510

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.

Upvotes: 1

Related Questions