开发者

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]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜