Error in Android's clearCheck() for RadioGroup?

后端 未结 3 525
盖世英雄少女心
盖世英雄少女心 2021-01-02 03:04

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

相关标签:
3条回答
  • 2021-01-02 03:22

    I had similar problem. My solution:

    in procedure:

    public void onCheckedChanged(RadioGroup rGroup, int checkedId)
    

    I check checkedId. It equals to -1 if you use clearCheck() else it equals to selected radiogroup child

    0 讨论(0)
  • 2021-01-02 03:26

    I faced the same problem and i solved with other work-around.

    1. Set CheckedChangeListener as NULL
    2. Do your operation
    3. Reset your OnCheckedChangeListener again

    Code snnipet :

    rdbGroup.setOnCheckedChangeListener(null);
    rdbGroup.clearCheck();
    rdbGroup.setOnCheckedChangeListener(checkedChangeListener);
    

    Hope this will help ツ

    0 讨论(0)
  • 2021-01-02 03:28

    What I've discovered is that if an item is checked and you call clearCheck() on the radio group it will call onCheckedChanged twice. The first time with the id of the item that was checked and the second time with -1/View.NO_ID. IMHO, this is a bug and apparently it has been around since at least 1.6. See this google code bug report: http://code.google.com/p/android/issues/detail?id=4785

    It seems to be that the only solution is to check the actual RadioButton.isChecked() and test if it is true or false. This sort of defeats the purpose of the onCheckedChanged returning the id of the item since you now have to either keep references to those buttons or call findViewById every time.

    I doubt they will fix this since changing it would probably break existing code in unexpected ways.

    0 讨论(0)
提交回复
热议问题