The program works and comes up. When I click start on the main menu it brings up a question (textview) and 4 answers (buttons). Text is assigned to the textview and the 4 buttons with the for-loop. It is never looping through after clicking a button. Nothing happens when clicking a button.
I have tried putting in a "break" and changing to a while loop and just can't get it working. I think this is a simple fix that I just cannot find.
Any other code structure or advice is appreciated and needed!
public class QuestionView extends Activity {
Quiz quiz = new Quiz();
ArrayList<Question> queries = quiz.getRandom10();
int correctAnswers = 0;
int wrongAnswers = 0;
int answer = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.questionviewmain);
TextView question = (TextView)findViewById(R.id.question);
Button answer1 = (Button)findViewById(R.id.answer1);
Button answer2 = (Button)findViewById(R.id.answer2);
Button answer3 = (Button)findViewById(R.id.answer3);
Button answer4 = (Button)findViewById(R.id.answer4);
for(int i = 0; i < 10; i++) {
question.setText(queries.get(i).getQuery());
answer1.setText(queries.get(i).getA1());
answer2.setText(queries.get(i).getA2());
answer3.setText(queries.get(i).getA3());
answer4.setText(queries.get(i).getA4());
answer = queries.get(i).getCorrectAnswer();
answer1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
if(answer == 0) {
correctAnswers++;
} else {
wrongAnswers++;
}
}
});
answer2.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
if(answer == 1) {
correctAnswers++;
} else {
wrongAnswers++;
}
}
});
answer3.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
if(answer == 2) {
correctAnswers++;
} else {
wrongAnswers++;
}
}
});
answer4.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
if(answer == 3) {
correctAnswers++;
} else {
wrongAnswers++;
}
}
});
}
}
}