Similar question to Android: Set a random image using setImageResource, but I think I'm looking for a different answer.
As mentioned in the linked post, this:
int p = R.drawable.photo;
image.setImageResource(p);
displays photo1, but something like this:
String a = "R.drawable.";
String b = "photo";
String c = a+b;
int p = Integer.parseInt(c);
image.setImageResource(p);
will not. I have a lot of images, and an array contining all of the image names, so I want to fill an array something like:
int imageArray[] = new int[number_of_images];
for (int i = 0; i < numImages; i++)
imageArray[i] = ("R.drawable." + image_names[i]);
but I get a runtime error. Is there any way to make this loop work? Or better ways to cue up image ID's into an array?
Thanks!