Quizzer (hw1)
A super simple five question Quiz app.
Only two classe were necessary, the QuestionDatabase class and the QuizzerActivity class.
All scoring and display programming was done in the Activity class
onCreate initialized the questions and score, and requested the GUI to display the first question
updateScore figured out which radioButton was checked from the multiple-choice answer list, and scored accordingly.
nextQuestion simply requested the next question. One issue I had here was an out of bounds exception when utilizing
int answerID = ((RadioGroup) findViewById(R.id.answerGroup).getCheckedRadioButtonId();
Simply calling the getCheckedRadiobuttonID() created this exception, thus my hack..
RadioButton answer0 = (RadioButton)findViewById(R.id.answer0);
if (answer0.isChecked()) answerID = 0;
RadioButton answer1 = (RadioButton)findViewById(R.id.answer1);
if (answer1.isChecked()) answerID = 1;
RadioButton answer2 = (RadioButton)findViewById(R.id.answer2);
if (answer2.isChecked()) answerID = 2;
The QuestionDatabase class is simply a collection of String[]’s, each with the display question, the 3 possible answers, and the final correct answer and is easily extensable.
It’s public methods request this data for the Activity class to display it, figure out if the radio index the user selected is correct, and resets the Game to be played again.