getResourceEntryName一个数组项 [英] getResourceEntryName for an array item

查看:2503
本文介绍了getResourceEntryName一个数组项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串数组中的strings.xml详情如下:

I have a string array in strings.xml as detailed below:

<string-array name="spinerArray">
    <item name="one">First</item>
    <item name="two">Second</item>
    <item name="three">Third</item>
    <item name="four">Fourth</item>
</string-array>

和我需要检索的项目一个名称不是值(一,二,三,四)。到目前为止,我知道这是可能获得使用getResourceEntryName像数组的名称:

And I need to retrieve one of the items name not the value (one, two, three, four). So far, I know it's possible to get the name of the array using getResourceEntryName like:

getResources().getResourceEntryName(R.array.spinerArray);

有没有办法让一个项目的名字吗?

Is there a way to get an item name?

感谢。

推荐答案

另一种解决方案:

Resources res = getResources();
TypedArray entriesTypedArray = res.obtainTypedArray(R.array.spinerArray);
ArrayList entriesName = new ArrayList();
TypedValue v1 = new TypedValue();
for (int i1=0; i1<entriesTypedArray.length(); i1++) {
    entriesTypedArray.getValue(i1, v1);
    String name1 = res.getResourceEntryName(v1.resourceId);
    entriesName.add(name1);
}

这篇关于getResourceEntryName一个数组项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆