I'm trying to set the default value of a ListPreference
programmatically, but it has no effect. I am inflating the preference from xml, and then setting the values dynamically.
addPreferencesFromResource(R.xml.pref_general);
ListPreference sizePreference = findPreference("picture_size");
sizePreference.setEntries(entries);
sizePreference.setEntryValues(entryValues);
sizePreference.setDefaultValue(entryValues[0]);
bindPreferenceSummaryToValue(sizePreference);
Is there a way to do this without having to override Preference
?
尝试这个:
setValueIndex(int index);
你试过setValueIndex(int index)吗?
sizePreference.setValueIndex(0);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.