プログラムで 5 (5) ボタンの ID を設定し、毎回シャッフルしようとしています。
シャッフルも問題ありません。
シャッフルして 5 つのボタンの ID を設定し、それぞれのテキストを設定する 2 つのメソッドを使用すると、エラーが発生します。
for-each ループを試すのは初めてなので、これが混乱する可能性があることはわかっています。
助けてください。ありがとうございました。
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));
}
}
}