samedi 18 février 2017

how to set ID for random ImageButton?

Hey guys I am new to Android.... I have 150 images how I can set IDs for them and make the button change the Image depending on the randomly generated ID? I started like that:

rand = new Random(System.currentTimeMillis());
    x = rand.nextInt(3);
    y = rand.nextInt(8);
    z = rand.nextInt(10);
String myID = "R.id.myImage_" + x + y + z;

I tried to use getResources but it needs context because I am working with on-activity class, but I read that context leads to Memory leaks so is there anyway to do that without context?




Aucun commentaire:

Enregistrer un commentaire