Convert String containing an ID into an Integer-ID

后端 未结 6 1567
别那么骄傲
别那么骄傲 2020-12-10 03:57

I have a short question:

How is it possible to convert a String, containing the Id of a Drawable, which is

String idString = \"R.drawable.bubblegum\"         


        
6条回答
  •  离开以前
    2020-12-10 04:36

    Call getIdentifier() on the Resources object you get via getResources(), as seen in these StackOverflow questions:

    • Is possible in Android to findView by String id?
    • Android findViewbyId with a variant string
    • How to access R.string.xxx resources from a method by passing string 'xxx' as parameter to that method?
    • Dynamically build a resource Identifier
    • How to access the values from strings.xml dynamically?
    • Drawable resource using a variable

    among others.

提交回复
热议问题