jeudi 4 février 2016

how set button text randomly without repeating?

i have :

String str[] = { "1", "2", "3", "4", "5", "6" };
Button buttons[] = new Button[4];

        buttons[0] = (Button) findViewById(R.id.id1);
        buttons[1] = (Button) findViewById(R.id.id2);
        buttons[2] = (Button) findViewById(R.id.id3);
        buttons[3] = (Button) findViewById(R.id.id4);

for (int i = 0; i < 4; i++) {
        Random r = new Random();
        int x = r.nextInt(str.length); 
        buttons[i].setText(str[x]);
                    }

so how can i set buttons text without repeating?




Aucun commentaire:

Enregistrer un commentaire