Halle
Halle

Reputation: 11

Resource issue, (R.drawable.*VARIABLE HERE*); possible?! ANDROID

I'm having an arrayList with loads of numbers, I want to have a different image on every number in the array represented by each number... but I dont know how to put a Variable in (R.drawable."HERE"), if its even possible?!

This is what i've tried to do, Im pretty new to android and Java, so this may seem pretty funny to you haha... (the array is not shown)

    String s = names[position];
    String img = s.toString();
    holder.imageView.setImageResource(R.drawable.img);

Hope you understand my question.

Thanks in advance

//Halle

Upvotes: 1

Views: 1759

Answers (1)

user180100
user180100

Reputation:

You can use reflection do do that. See here for an example.

Upvotes: 1

Related Questions