Android SDK - 获取字符串值的R.id(int)

时间:2010-10-26 17:26:30

标签: android

假设我有一个名为test1.xml的xml文件,其格式为String xmlFile =“test1.xml”。我怎样才能获得它的R.id.test1值?

1 个答案:

答案 0 :(得分:3)

我认为您需要getIdentifier (String name, String defType, String defPackage)类中的Resources方法。这是documentation

但是这种方法很慢,请注意以下文档:

  

注意:不鼓励使用此功能。按标识符检索资源比按名称检索资源要高效得多。

这是另一个类似的问题:get resource id by passing name as a parameter in android