2010-05-19 18 views
17

在arrays.xml在XML数组引用的XML字符串(机器人)

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

在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> 

我想引用字符串数组“我的项目1中“来自strings.xml。我怎么做?

回答

29

哦,是的,这就是我的意思。这是我做到的。

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

它在Android 1.6的正确解析

+2

这对我不工作,如果他们是在同一个XML文件...我想我要补充一点,重要的注意事项*与Eclipse 4.2 – 2012-07-31 20:48:03

+0

如果--using的Ubuntu无法识别'@ string',请尝试将它输入到IDE中,而不是复制和粘贴。 – brandall 2016-03-28 21:10:50

8

你不能。它可能可以做相反的:在<string-array>@string/item1