1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
private void setButton() {
//Bouton placer statiquement que je récupère dans une liste pour l'utiliser
buttonList.add((Button)findViewById(R.id.Button01));
buttonList.add((Button)findViewById(R.id.Button02));
buttonList.add((Button)findViewById(R.id.Button03));
buttonList.add((Button)findViewById(R.id.Button04));
buttonList.add((Button)findViewById(R.id.Button05));
buttonList.add((Button)findViewById(R.id.Button06));
buttonList.add((Button)findViewById(R.id.Button07));
buttonList.add((Button)findViewById(R.id.Button08));
buttonList.add((Button)findViewById(R.id.Button09));
buttonList.add((Button)findViewById(R.id.Button10));
buttonList.add((Button)findViewById(R.id.Button11));
buttonList.add((Button)findViewById(R.id.Button12));
buttonList.add((Button)findViewById(R.id.Button13));
buttonList.add((Button)findViewById(R.id.Button14));
//Liste de lettre a rajouter pour completer les boutons
ArrayList<String>lettreEnPlus = new ArrayList<String>();
lettreEnPlus.addAll(Arrays.asList("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"));
//Liste de valeur a donner au boutons
ArrayList<String>tmp = new ArrayList<String>();
//Pour garder la reponse_List pour les comparaisons de reponse
tmp.addAll(reponse_List);
int index = 0;
int i = tmp.size();
//On rajoute des valeurs au fond de la liste des possibilité (14 Bouttons)
while(i < buttonList.size())
{
index = (int) Math.round(Math.random()*lettreEnPlus.size());
tmp.add(lettreEnPlus.get(index));
i++;
}
//On melange
Collections.shuffle(tmp);
//Puis on affecte a chaque bouton une nouvelle lettre ainsi qu'un evenement
for ( i = 0; i < buttonList.size();i++)
{
buttonList.get(i).setText(tmp.get(i));
buttonList.get(i).setOnClickListener(this);
}
} |
Partager