// strings.xml
<string-array name="list">
<item>Istinye Park</item>
<item>Kanyon Istanbul</item>
<item>Akmerkez</item>
<item>Forum Istanbul</item>
<item>Istanbul Cevahir</item>
<item>Metrocity</item>
<item>Istanbul Sapphire</item>
</string-array>
我需要从 java 访问字符串数组的特定项。我可以使用 R.string.str
访问字符串并使用 R.array.list
访问数组。但是需要像 R.array.list[1]
这样的东西来访问特定的数组项。
最佳答案
您可以使用 getStringArray
通过资源加载它,然后像操作标准数组一样操作它。
Resources res = getResources(); //assuming in an activity for example, otherwise you can provide a context.
String[] shoppingItems = res.getStringArray(R.array.shopping);
String istanbul = shoppingItems[1]; //Kanyon Istanbul
关于java - 如何从java中的字符串数组中获取项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28454027/