RadioGroup calls onCheckChanged() three times
android, radio-button, radio-group
Solution
So, is there a way to avoid multiple event raising ?
Call `b.setChecked(true);` instead.
A quick look through the source code confirms that `RadioGroup#check()` really does call the OnCheckChangedListener three times...
- When the current selection is unchecked,
- When the new RadioButton is checked, and
- When the RadioGroup saves which RadioButton is now checked.
Odd quirk.
Problem
I've been struggling with an issue of programmatic checking of a RadioButton, which is situated in a RadioGroup. It seems that a single `check()` call raises three events - once for the first RadioButton and twice for the second, which is my target. At the same time clicking on the second RadioButton in the interface causes only one event to appear, which is correct. So, is there a way to avoid multiple event raising ? ``` public class RadiogroupActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); RadioGroup r = (RadioGroup) findViewById(R.id.radioGroup1); RadioButton b = (RadioButton) findViewById(R.id.radio1); r.setOnCheckedChangeListener(onPromobuttonsClick); r.check(R.id.radio1); } private OnCheckedChangeListener onPromobuttonsClick = new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { Log.d("x", "x"); } }; } ```