How-to init a ListPreference to one of its values

Viewed 43236

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

Here is an sample of my preference.xml file:

<ListPreference android:key="notification_delay"
    android:title="@string/settings_push_delay"
    android:entries="@array/settings_push_delay_human_value"
    android:entryValues="@array/settings_push_delay_phone_value"
    android:defaultValue="????">
</ListPreference>

The two arrays:

<string-array name="settings_push_delay_human_value">
    <item>every 5 minutes</item>
    <item>every 10 minutes</item>
    <item>every 15 minutes</item>
</string-array>
<string-array
    name="settings_push_delay_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_delay"
    android:title="@string/settings_push_delay"
    android:entries="@array/settings_push_delay_human_value"
    android:entryValues="@array/settings_push_delay_phone_value"
    android:defaultValue="1">
</ListPreference>

Any Idea?

4 Answers
Related