listpreference
How to set the Default Value of a ListPreference
You don’t need to programmatically handle the default value of ListPreferences. You can do this in xml setting file. Below is an example <string-array name=”opts”> <item>red</item> <item>green</item> <item>blue</item> </string-array> <string-array name=”opts_values”> <item>1</item> <item>2</item> <item>3</item> </string-array> … <ListPreference android:title=”Colour select” android:summary=”Select your favourite” android:key=”colour” android:entries=”@array/opts” android:entryValues=”@array/opts_values” android:defaultValue=”2″ /> here I selected 2 as a default value. … Read more
ListPreference: use string-array as Entry and integer-array as Entry Values doesn’t work
The answer is simple: because the Android is designed this way. It just uses String arrays for both entries and entry values and that’s all. And I can’t see any problem in this fact, since you can easily convert a String to an int using the Integer.parseInt() method.