如何创建一个带有复选框
的ListPreference
?
我知道如何使用 ListPreference
,但我需要像在“重复”首选项的警报应用程序中那样进行多项选择。
喜欢这个截图:
最佳答案
从 API 11 开始,您可以使用 MultiSelectListPreference
String[] selections = {"selection1","Selection2"};
Set<String> selectionSet = new HashSet<String>();
selectionSet.addAll(Arrays.asList(selections));
MultiSelectListPreference multiSelectPref = new MultiSelectListPreference(this);
multiSelectPref.setKey("multi_pref");
multiSelectPref.setTitle("Multi Select List Preference");
multiSelectPref.setEntries(selections);
multiSelectPref.setEntryValues(selections);
multiSelectPref.setDefaultValue(selectionSet);
getPreferenceScreen().addPreference(multiSelectPref);
关于android - 如何使用复选框创建 ListPreference,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4085186/