vendredi 13 janvier 2017

Change ImageButton Resource Randomly

I have 320 images in drawable and I have an ImageButton so when it's pressed I want the Image to be changed randomly, the image name is like this file_xyz, the xyz are numbers each one generated randomly using this code:

rand = new Random(System.currentTimeMillis()); x = rand.nextInt(3 - 0) + 0; y = rand.nextInt(7 - 0) + 0; z = rand.nextInt(9 - 0) + 0; return "shape_" + x+ y+ z;

so this give me a string which I want to use it to change the resource of ImageButton, so how I can do this ?




Aucun commentaire:

Enregistrer un commentaire