Android: ListPreference setDefaultValue()
Why its not work in Code ? in XML its ok, but not in Code.
String [] testVal开发者_JAVA技巧ues = {"a" , "b", "c"};
ListPreference test = (ListPreference)findPreference(KEY);
test.setEntries(testValues);
test.setEntryValues(testValues);
test.setDefaultValue(testValue[0]);
How to set the Default Value of a ListPreference
you can also try test.setValueIndex(0);
Instead of using setDefaultValue
on ListPreference
, you may use setValue
to change the value. The complete code would be:
String [] testValues = {"a" , "b", "c"};
ListPreference test = (ListPreference)findPreference(KEY);
test.setEntries(testValues);
test.setEntryValues(testValues);
test.setValue(testValue[0]);
精彩评论