I need a help with setting a random image using setImageResource method. In the drawable folder, I have a jpeg file named photo0.jpg, photo1.jpg...photo99.jpg. And the following code works:
int p = R.drawable.photo1;
image.setImageResource(p);
The above will display photo1.jpg but I want to show a random image. I tried the following but it doesn t work.
String a = "R.drawable.photo";
int n = (int) (Math.random()*100)
String b = Integer.toString(n);
String c = a+b;
int p = Integer.parseInt(c);//checkpoint
image.setImageResource(p);
It seems like the string "R.drawable.photoXX" isn t being changed to integer at the checkpoint. Could someone please teach me a right code? Thank you in advance.