Reference a specific item in a <string-array> from a preferences XML?

血红的双手。 提交于 2019-12-11 22:49:58

问题


Assuming I have a string array defined as:

<string-array name="settings">
    <item>not very unique</item>
    <item>not very unique</item>
    <item>slightly more unique</item>
</string-array>

Is there a way to reference an item, by its index in the array, from a preferences XML?

I know how to reference the entire array:

android:entries="@array/settings" 

But is there a way to reference only one item from the array?


回答1:


Well no, there is no way, but you could do something like this:

<string name="mystring_1">awesome string is awesome</string>
<string name="mystring_2">even more awesome string</string>
<string-array name="mystrings">
    <item>@string/mystring_1</item>
    <item>@string/mystring_2</item>     
</string-array>

So you basically reference another string in your resources, that is referenced in your string array. ;)



来源:https://stackoverflow.com/questions/7251595/reference-a-specific-item-in-a-string-array-from-a-preferences-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!