If I get the image name as a variable like following:
var imageName = SERVICE.getImg();
Then, how can I get the resource with R.drawable.????, I tried R.drawable[imageName], but it failed. Any suggestions?
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.
This will get you the ID of the resource you are looking for. With it, you can then access the resource from the R class.
Using only the
nameparameter:You can also include all the 3 info in the “name” parameter using the following format:
"package:type/image_name", something like:This is useful when you’re working with external components or libraries that you can’t, or don’t want to, change how
getIdentifier()is called. e.g.: AOSP Launcher3