I have a xml file (/res/xml/setting.xml) for PreferenceActivity:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Main Settings">
<ListPreference
android:title="Background Image"
android:summary="Set the background image"
android:key="key_background"
android:entries="@array/background"
android:entryValues="@array/background_values"
android:defaultValue="winter.png" />
</PreferenceCategory>
</PreferenceScreen>
Then I have another xml file "/res/values/string.xml":
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="background">
<item>Winter</item>
<item>Desert</item>
</string-array>
<string-array name="background_values">
<item>winter.png</item>
<item>desert.png</item>
</string-array>
</resources>
See ListPreference in setting.xml, I want android:defaultValue to be set with winter.png. But I also don't want to be set with hardcoded/constant value in the xml, so I tried with various values such as "@array/background_values/0", "@array/background_values[0]", etc...but all failed.
So, the questions are:
- What is the correct syntax for accesing an item of string-array resource in other xml?
- How to make sure if the
android:defaultValueis working? - Is there any documentation about the
@arraysyntax? I can't found any.