Error in Android's clearCheck() for RadioGroup?
Posted
by
Manuel R. Ciosici
on Stack Overflow
See other posts from Stack Overflow
or by Manuel R. Ciosici
Published on 2010-12-23T13:22:44Z
Indexed on
2010/12/30
5:53 UTC
Read the original article
Hit count: 196
android
|android-emulator
I'm having an issue with RadioGroup's clearChecked(). I'm displaying a multiple choice question to the user and after the user selects an answer I check the answer, give him some feedback and then move to the next question. In the process of moving to the next question I clearCheck on the RadioGroup.
Can anyone explain to me why the onCheckedChanged method is called 3 times? Once when the change actually occurs (with the user changes), once when I clearCheck(with -1 as the selected id) and once in between (with the user changes again)?
As far as I could tell the second trigger is provoked by clearCheck. Code below:
private void checkAnswer(RadioGroup group, int checkedId){
// this makes sure it doesn't blow up when the check is cleared
// also we don't check the answer when there is no answer
if (checkedId == -1) return;
if (group.getCheckedRadioButtonId() == -1) return;
// check if correct answer
if (checkedId == validAnswerId){
score++;
this.giveFeedBack(feedBackType.GOOD);
} else {
this.giveFeedBack(feedBackType.BAD);
}
// allow for user to see feedback and move to next question
h.postDelayed(this, 800);
}
private void changeToQuestion(int questionNumber){
if (questionNumber >= this.questionSet.size()){
// means we are past the question set
// we're going to the score activity
this.goToScoreActivity();
return;
}
//clearing the check
gr.clearCheck();
// give change the feedback back to question
imgFeedback.setImageResource(R.drawable.question_mark); //OTHER CODE HERE
}
and the run method looks like this
public void run() {
questionNumber++;
changeToQuestion(questionNumber);
}
© Stack Overflow or respective owner