views:

25

answers:

1

Hi.

I am using following code in preferences page in android to show a list of items. The list and values are located in a file at location "app/res/xml/time.xml"

 <ListPreference
           android:title="Time unit list"
           android:summary="Select the time unit"
           android:dependency="Main_Option"
           android:key="listPref"
           android:defaultValue="1"
           android:entries="?xml:time/timet"
           android:entryValues="@xml:time/timet_values" />

The code for the time.xml is as follow:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="timet">
        <item>seconds</item>
        <item>minutes</item>
        <item>hours</item>
    </string-array>

    <string-array name="timet_values">
        <item>3600</item>
        <item>60</item>
        <item>1</item>
    </string-array>
</resources>

I am not able to reference these values in my preference xml file. (The code snippet above). It gives an error. How can I specify packaged path for the List preferences entry and entry_values

Any help is appreciated. Cheers

+1  A: 

You should references the string-array elements by name:

<ListPreference
           android:title="Time unit list"
           android:summary="Select the time unit"
           android:dependency="Main_Option"
           android:key="listPref"
           android:defaultValue="1"
           android:entries="@array/timet"
           android:entryValues="@array/timet_values" />
Dave Webb
I think, along with that that error was, that time.xml should have been in values folder; thereby giving me direct access to the ids.
Priyank