I have an app where there is one constant background image. I want to change this background image randomly on click. How do I do it?
Asked
Active
Viewed 645 times
-3
-
1Possible duplicate of [Changing background image on button click android app development](http://stackoverflow.com/questions/29735869/changing-background-image-on-button-click-android-app-development) – Sanoop Surendran Jul 15 '16 at 05:48
1 Answers
0
int images[] = {R.drawable.image1, R.drawable.image2, R.drawable.image2};
view.setBackgroundDrawable(getResources.getDrawable(image[new Random().nextInt(images.length())]));
Create an array of your drawable set the background of the view using the drawable on the images array so you need a random index.

mariozawa
- 1,504
- 1
- 11
- 14