I am making a quiz game similar to the logo quizzes and im trying to create the input style on which they apps have. They have random mixed up letters and the user has to find the letter which make up the correct answer. So far i have an array list that hold the buttons and the correct answers letters, then i loop through the array lists and assign the buttons text to the letters from the correct answers array list but causing a force stop with no errors. Anyone know why?
ArrayList<Character> answer = new ArrayList<Character>();
ArrayList<Button> buttons = new ArrayList<Button>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn1 = (Button) findViewById(R.id.button1);
Button btn2 = (Button) findViewById(R.id.button2);
Button btn3 = (Button) findViewById(R.id.button3);
Button btn4 = (Button) findViewById(R.id.button4);
Button btn5 = (Button) findViewById(R.id.button5);
Button btn6 = (Button) findViewById(R.id.button6);
Button btn7 = (Button) findViewById(R.id.button7);
Button btn8 = (Button) findViewById(R.id.button8);
Button btn9 = (Button) findViewById(R.id.button9);
buttons.add(btn1);
buttons.add(btn2);
buttons.add(btn3);
buttons.add(btn4);
buttons.add(btn5);
buttons.add(btn6);
buttons.add(btn7);
buttons.add(btn8);
buttons.add(btn9);
String testAnswer = "Answer";
//convert to chars and add to arraylist for shuffling
for(char a : testAnswer.toCharArray()){
answer.add(a);
}
Collections.shuffle(answer);
//loop over buttons and letters and assign each button with a letter
for(char a : answer){
for(Button bb : buttons){
bb.setText(String.valueOf(a));
}
}
}
foris doing.)for (char a : testAnswer.toCharArray()) { answer.add(a); }you should writeanswer = new ArrayList<Character>(Arrays.asList(testAnswer.toCharArray()));.