tags:

views:

48

answers:

1

I'm trying to set a defaultValue to a ListPreference item.

Here is an sample of my preference.xml file:

<ListPreference android:key="notification_delai"
    android:title="@string/settings_push_delai"
    android:entries="@array/settings_push_delai_human_value"
    android:entryValues="@array/settings_push_delai_phone_value"
    android:defaultValue="????">
</ListPreference>

The two arrays:

<string-array name="settings_push_delai_human_value">
    <item>every 5 minutes</item>
    <item>every 10 minutes</item>
    <item>every 15 minutes</item>
</string-array>
<string-array
    name="settings_push_delai_phone_value">
    <item>300</item>
    <item>600</item>
    <item>900</item>
</string-array>

When i go into the preference activity, no item of the ListPreference is selected. I've tried to set an int value like 1 in the "android:defaultValue" fied to select "10 minutes" but it does not work.

<ListPreference android:key="notification_delai"
    android:title="@string/settings_push_delai"
    android:entries="@array/settings_push_delai_human_value"
    android:entryValues="@array/settings_push_delai_phone_value"
    android:defaultValue="1">
</ListPreference>

Any Idea?

+1  A: 

You need to specify the value. So to get the first entry selected by default specify defaultValue="300" in your example.

sven
This works well, programmatically I have a 300 value. But in fact what I'd like is to select "graphically" one of the rows of the ListPreference by default.
ol_v_er
In my application it does exactly that: The value specified for "defaultValue" is selected in the preferences list, when the app is started for the first time. Don't why this shouldn't work for you...
sven
Sorry my mistake. I made an error between the default values and the values in the array. It works fine on all the phones I tried. Thanks.
ol_v_er