-3

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?

Sathish Kumar J
  • 4,280
  • 1
  • 20
  • 48
Sanik
  • 35
  • 12
  • 1
    Possible 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 Answers1

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