Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android中的错误';是否为RadioGroup设置了clearCheck()?_Android_Android Emulator - Fatal编程技术网

Android中的错误';是否为RadioGroup设置了clearCheck()?

Android中的错误';是否为RadioGroup设置了clearCheck()?,android,android-emulator,Android,Android Emulator,我对RadioGroup的clearChecked()有问题。我向用户显示一个选择题,在用户选择答案后,我检查答案,给他一些反馈,然后转到下一个问题。在进入下一个问题的过程中,我清楚地检查了放射组 有人能解释一下为什么onCheckedChanged方法被调用了3次吗?一次是在实际发生更改时(用户更改),一次是在我clearCheck时(选择-1作为id),一次是在两者之间(用户再次更改) 据我所知,第二个触发器是由clearCheck触发的。代码如下: private void checkAn

我对RadioGroup的clearChecked()有问题。我向用户显示一个选择题,在用户选择答案后,我检查答案,给他一些反馈,然后转到下一个问题。在进入下一个问题的过程中,我清楚地检查了放射组

有人能解释一下为什么onCheckedChanged方法被调用了3次吗?一次是在实际发生更改时(用户更改),一次是在我clearCheck时(选择-1作为id),一次是在两者之间(用户再次更改)

据我所知,第二个触发器是由clearCheck触发的。代码如下:

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
}
run方法如下所示

public void run() {
        questionNumber++;
        changeToQuestion(questionNumber);
    }

我发现,如果一个项目被选中,你在无线组中调用
clearCheck()
,它将调用
onCheckedChanged
两次。第一次使用选中项目的id,第二次使用
-1
/
视图。无id
。IMHO,这是一个bug,显然它至少在1.6版本就已经存在了。请参阅此google代码错误报告:

似乎唯一的解决方案是检查实际的
RadioButton.isChecked()
,并测试它是否正确。这种情况违背了
onCheckedChanged
返回项目id的目的,因为您现在必须保留对这些按钮的引用,或者每次调用
findViewById


我怀疑他们会解决这个问题,因为更改它可能会以意外的方式破坏现有代码。

我也有类似的问题。我的解决方案:

在程序上:

public void onCheckedChanged(RadioGroup rGroup, int checkedId)
我查一查。如果使用clearCheck(),它等于-1
否则它等于所选的放射组孩子

我面临同样的问题,我用其他解决方法解决了这个问题

  • 将CheckedChangeListener设置为空
  • 做手术
  • 再次重置OnCheckedChangeListener
  • 代码snnipet:
    希望这会有所帮助ツ

    @qbeticus谢谢你,我最终设法使用了一个布尔变量来确定onCheckedChanged是否应该继续计算checked选项。感谢你确认这是一个bug,我在看到radiogroup的怪异行为后怀疑它。
    rdbGroup.setOnCheckedChangeListener(null);
    rdbGroup.clearCheck();
    rdbGroup.setOnCheckedChangeListener(checkedChangeListener);