从字符串值获取资源ID [英] Retrieving resource id from string value

查看:132
本文介绍了从字符串值获取资源ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何从字符串的名称是在strings.xml中present检索渣油

I know how to retrieve a resID from the name of the string which is present in strings.xml

        <string name="text">Chennai</string>

我们可以通过下面的检索渣油

We can retrieve the resID by following

          int id = this.context.getResources().getIdentifier("text","string", this.context.getPackageName());

使用值如何获取ID的是有可能做或它不可能
任何帮助AP preciated

How can retrieve the id by using the value Chennai is it possible to do or its impossible any help is appreciated

推荐答案

它作为唯一的字符串值不要求是不可能的。因此,你不能获得ID后面是潜在你可以有多个ID映射到相同的字符串。

It's not possible as the string values are not required to be unique. Therefore you can't get "the id" back as potentially you could have multiple ids mapping to the same string.

例如:

<string name="text">Chennai</string>
<string name="text2">Chennai</string>
<string name="text3">Chennai</string>

是完全可以接受的。你怎么能得到的ID后面的字符串奈?

is completely acceptable. How can you get "the id" back for the string "Chennai"?

这篇关于从字符串值获取资源ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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