Android SDK中 - 得到一个字符串值R.id(INT) [英] Android SDK - get R.id (int) of a string value

查看:513
本文介绍了Android SDK中 - 得到一个字符串值R.id(INT)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以说我有一个名为test1.xml在字符串XMLFILE =test1.xml格式的XML文件。我怎样才能得到它的R.id.test1价值?

Lets say I have an xml file called test1.xml in String xmlFile = "test1.xml" format. How can I get the R.id.test1 value of it?

推荐答案

我想你想中的则getIdentifier(字符串名称,字符串DEFTYPE,字符串defPackage)方法资源类。这里是<一个href=\"http://developer.android.com/reference/android/content/res/Resources.html#getIdentifier%28java.lang.String,%20java.lang.String,%20java.lang.String%29\"相对=nofollow>文档。

I think you want the getIdentifier (String name, String defType, String defPackage) method within the Resources class. Here is the documentation.

但是,这种做法是相当缓慢的,注意从文档如下:

However this approach is quite slow, note the following from the docs:

请注意:使用此功能被劝阻。它是更有效的由标识符不是名称检索资源。

Note: use of this function is discouraged. It is much more efficient to retrieve resources by identifier than by name.

下面是另外一个类似的问题:<一href=\"http://stackoverflow.com/questions/3476430/get-resource-id-by-passing-name-as-a-parameter-in-android\">get在Android的传递名作为参数的资源ID

Here is another similar question: get resource id by passing name as a parameter in android

这篇关于Android SDK中 - 得到一个字符串值R.id(INT)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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