I have a imageView, button inside an activity, 10 pictures that are named from stage1 to stage9.
I need you help to solve some problem
I would like to use a button click to change picture that is on imageView to the next one.
I mean, I want to press on the button, and image view shows stage2 image, I press the button again and stage3 picture will be shown.
I have done this using counter var which count number of clicks and then running if statment to see which picture should go next, but it is too long and it is not possible to have more or less pictures.
I would like to know is there a way to do this, and if possible please show me how.
Thanks
code
private void changeImage(int counter) {
if (counter == 1) {
image.setImageResource(R.drawable.stage2);
} else if (counter == 2) {
image.setImageResource(R.drawable.stage3);
} else if (counter == 3) {
image.setImageResource(R.drawable.stage4);
} else if (counter == 4) {
image.setImageResource(R.drawable.stage5);
} else if (counter == 5) {
image.setImageResource(R.drawable.stage6);
} else if (counter == 6) {
image.setImageResource(R.drawable.stage7);
} else if (counter == 7) {
image.setImageResource(R.drawable.stage8);
} else if (counter == 8) {
image.setImageResource(R.drawable.stage9);
}
}
bassically this is the code that I am using right now.
It works, but if I want to do it to be more dynamic.