Sunday 4 December 2011

ListPreference with values number type

In my Android application I tried to define preferences list with values of number type.
<ListPreference
      android:key="poll_list"
      android:title="@string/preference_poll_list"
      android:summary="@string/preference_poll_list_summary"
      android:entries="@array/poll_option"
      android:entryValues="@array/poll_option_values"
      android:dialogTitle="@string/preference_poll_list" />
I had to define lists in arrays.xml. But I had to define list poll_option_values as a string-array, like here:
<resources>
    <array name="poll_option">
        <item>1 Minute</item>
        <item>2 Minutes</item>
        <item>5 Minutes</item>
        <item>10 Minutes</item>
        <item>20 Minutes</item>
    </array>
    <string-array name="poll_option_values">
        <item>60</item>
        <item>120</item>
        <item>300</item>
        <item>600</item>
        <item>1200</item>
    </string-array>
</resources>
I couldn't use array type. Just another Android feature ;)

No comments: