开发者

Android SDK - get R.id (int) of a string value

开发者 https://www.devze.com 2023-01-21 21:12 出处:网络
Lets say I have an xml file 开发者_如何学Pythoncalled test1.xml in String xmlFile = \"test1.xml\" format.How can I get the R.id.test1 value of it?I think you want the getIdentifier (String name, Strin

Lets say I have an xml file 开发者_如何学Pythoncalled test1.xml in String xmlFile = "test1.xml" format. How can I get the R.id.test1 value of it?


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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号