The string-array shall be placed in the file /res/values/arrays.xml
and not in /res/values/strings.xml
Each element of the array should not be hard-coded array but use a reference to a string defined in /res/values/strings.xml
.
To explain I will use an example taken from this tutorial.
First define the strings in /res/values/strings.xml
.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string
name="app_name">Choose Your Own</string>
<string
name="race_orc">Orc</string>
<string
name="race_elf">Elf</string>
<string
name="race_troll">Troll</string>
<string
name="race_human">Human</string>
<string
name="race_halfling">Halfling</string>
<string
name="race_goblin">Goblin</string>
</resources>
Then, using these strings, define the array in /res/values/arrays.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array
name="races_array">
<item>@string/race_goblin</item>
<item>@string/race_orc</item>
<item>@string/race_elf</item>
<item>@string/race_human</item>
<item>@string/race_troll</item>
<item>@string/race_halfling</item>
</string-array>
</resources>
In java to get a reference to string-array use:
String[] cRaces = getResources().getStringArray(R.array.races_array);
In xml, for example, in a Spinner you can use it this way:
<Spinner
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/spinnerOfCharacterRaces"
android:entries="@array/races_array">
</Spinner>
To access a particular array item you will not use the array but the string defined in /res/values/strings.xml
.
This allows using the name assigned to the string and not an index.
For example a button:
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/race_orc" />
Or in java:
String race = getResources().getText(R.string.race_orc);
It would be easier, in order to give an answer, to ask the question, xml of the string array.
– ramaral