我想在非首选项活动中显示ListPreference对话框。
下面是创建对话框的代码
// 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();
我的问题是对话框总是空的…
我错过了什么?
最佳答案
你不能这样做,Preference
应该在PreferenceScreen
中,并且活动必须扩展PreferenceActivity
。
我认为您希望实现一个对话框,显示选项列表,如ListPreference
do。我建议对列表视图使用AlertDialog
(基于arrayadapter)。
检查this例如或AlertDialog.Builder文档。