Jim
Jim

Reputation: 9234

Android: ListPreference setDefaultValue()

Why its not work in Code ? in XML its ok, but not in Code.

String [] testValues = {"a" , "b", "c"};
ListPreference test = (ListPreference)findPreference(KEY);
test.setEntries(testValues);
test.setEntryValues(testValues);
test.setDefaultValue(testValue[0]);

Upvotes: 2

Views: 4616

Answers (3)

VCD
VCD

Reputation: 949

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

Upvotes: -1

ungalcrys
ungalcrys

Reputation: 5620

you can also try test.setValueIndex(0);

Upvotes: 1

Related Questions