19

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?

jax
  • 36,355
  • 56
  • 177
  • 271

2 Answers2

35

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

jax
  • 36,355
  • 56
  • 177
  • 271
  • 2
    it doesnt work for me if they are in the same xml file...i thought i should add that important note* --using Ubuntu with Eclipse 4.2 – Samuel-Eli Jul 31 '12 at 20:48
  • If `@string` isn't recognised, try typing it into the IDE, rather than copying and pasting. – brandall Mar 28 '16 at 21:10
8

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

CommonsWare
  • 954,112
  • 185
  • 2,315
  • 2,367