java - Set image to random ImageView-Android -


i having annoying problem, because want set image random imageview in android. tell me how random imageview id. in advance

probably need set random image imageview's src. so: need define sources image . may declare them this:

int img1res = r.mipmap.img1id; int img2res = r.mipmap.img2id;

...

then create random int: random r = new random (); int ra = r.nextint(5);

when set 5 parameter in code above , states random numbers may 0, 1,2,3 , 4.

then , may check random number switch statement : switch (ra){ case 0 : imgview.setbackgroundresource (img1res); break; case 1: imgview.setbackgroumdresource (img2res): break; case ...... ....

}


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -