Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing an XML string in an XML Array (Android)

Tags:

android

in arrays.xml

<string-array name="my_items">
  <item>My item 1</item>
  <item>My item 2</item>
  <item>My item 3</item>
</string-array>

in strings.xml

<resources>
  <string name="item1">My item 1</string>
  <string name="item2">My item 2</string>
  <string name="item3">My item 3</string>
</resources>

I would like to reference the string in the array "My item 1" from strings.xml. How do I do that?

like image 954
jax Avatar asked May 19 '10 08:05

jax


People also ask

Where is strings XML in Android?

XML file saved at res/values/strings.

Where can I find strings in XML?

android-navigation/app/src/main/res/values/strings. xml.

Why do we use string XML in Android?

String. xml file contains all the strings which will be used frequently in Android project. String. xml file present in the values folder which is sub folder of res folder in project structure.In Android Studio, we have many Views such as TextView,Button,EditText,CheckBox,RadioButton etc.

What is string array in Android?

It is one of the most used data structure by programmers due to its efficient and productive nature; The Array is a collection of similar data type elements. It uses a contiguous memory location to store the elements. A String Array is an Array of a fixed number of String values. A String is a sequence of characters.


2 Answers

oh yeah, that is what I meant. This is how I did it.

<string-array name="my_items">
  <item>@string/item1</item>
  <item>@string/item2</item>
  <item>@string/item3</item>
</string-array>

It resolved correctly in Android 1.6

like image 161
jax Avatar answered Sep 22 '22 00:09

jax


You can't. It might be possible to do the reverse: have @string/item1 in the <string-array>.

like image 22
CommonsWare Avatar answered Sep 22 '22 00:09

CommonsWare