0

Hi I have some drawables that I run through via switch.

Is it possible run through these in a for statement instead?

Something like...

i=0;

String d = "tab"+i;

R.drawable.[d];

i++;

?

Thanks Aidan

aidanmack
  • 518
  • 1
  • 5
  • 16
  • it is possible using [getIdentifier](http://stackoverflow.com/questions/28772290/how-to-add-string-in-int-r-string-nameinteger-parsemyindex-not-working) – Blackbelt Oct 13 '15 at 15:42

1 Answers1

0

Yes, you can do something like this:

String d = "tab"+i;

int id = getActivity().getResources().getIdentifier(d,
                "drawable", getActivity().getPackageName());

Then set your image:

yourImageView.setImageResource(id);
SuperFrog
  • 7,631
  • 9
  • 51
  • 81