1

I have a table in the database which contains names of images: pic1, pic2, pic3 etc... When this table is retrieved from the db I need to create an array of drawbles from the names of the pics eg:

private Integer[] pics = {
  R.drawable.pic1, R.drawable.pic2,R.drawable.pic3}

The actuall images are in the drawable folder of the application.

How Can I achieve that?

10X!

1 Answer 1

1

You can use Resources.getIdentifier():

Resources res = context.getResources();
int id = res.getIdentifier("pic1", "drawable", context.getPackageName());
assert id == R.drawable.pic1;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.