say I want to dynamically load an image file in R.drawable.* based on the value of a string
Is there a way to do this? It seems like I need to statically refer to anything in R.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Have you declared the id for the image in XML file? If you did, you can use the following method:
Let’s say you have picture.png in your res/drawable folder.
In your activity, you can set your image resource in the main.xml file
In FirstActivity
imageString is the dynamic name. After which you can get the identifier of the dynamic resource.
Another method, you can do this:
You will be able to reference your image resource and set your ImageView to it.