3

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?

1 Answers1

3

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

Community
  • 1
  • 1
dave.c
  • 10,910
  • 5
  • 39
  • 62