I am trying to set the id's of 5 (five) buttons programatically and shuffle them every time.
There's no problem with shuffle.
I get errors when I use 2 (two) methods that shuffles and set id of 5 buttons AND set the texts of each one.
I know this could be a mess because it's my first time to try for-each loop.
Please help. Thank you.
Button b1, b2, b3, b4, b5;
Button[] buttons = { b1, b2, b3, b4, b5 };
public void shuffleButtons() {
Integer[] Id = { R.id.bChoice1, R.id.bChoice2, R.id.bChoice3,
R.id.bChoice4, R.id.bChoice5 };
ArrayList<Integer> buttonId = new ArrayList<Integer>(Arrays.asList(Id));
Collections.shuffle(buttonId);
for (int x = 0; x < 5; x++) {
for (Button b : buttons) {
b = (Button) findViewById(buttonId.get(x));
}
}
}
public void setButtonTxt() {
for (Button b : buttons) {
for (int x = 0; x <= buttons.length; x++) {
b.setText(textList.get(x));
}
}
}