Skip to content Skip to sidebar Skip to footer

Error In Android's Clearcheck() For Radiogroup?

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 f

Solution 1:

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.

Solution 2:

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 ツ

Solution 3:

I had similar problem. My solution:

in procedure:

publicvoidonCheckedChanged(RadioGroup rGroup, int checkedId)

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

Post a Comment for "Error In Android's Clearcheck() For Radiogroup?"