Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Check the API here:</p> <p><a href="http://developer.android.com/reference/android/widget/RadioGroup.OnCheckedChangeListener.html" rel="nofollow">http://developer.android.com/reference/android/widget/RadioGroup.OnCheckedChangeListener.html</a></p> <p>EDIT:</p> <p>Not happy about how long it took, but I figured this out. Turns out onCheckedChanged only passes -1 for the checkedId when the group is already clear. If a box has just been unchecked, its ID is still passed.</p> <p>You can do this:</p> <pre><code> myGroup2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){ @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if(checkedId != -1 &amp;&amp; ((RadioButton) findViewById(checkedId)).isChecked()){ myGroup3.clearCheck(); } } }); myGroup3.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){ @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if(checkedId != -1 &amp;&amp; ((RadioButton) findViewById(checkedId)).isChecked()){ myGroup2.clearCheck(); } } }); </code></pre> <p>Or, probably a little more sensibly, have the activity implement the listener and this part is outside of the onCreate method:</p> <pre><code>@Override public void onCheckedChanged(RadioGroup group, int checkedId) { if(checkedId != -1 &amp;&amp; ((RadioButton) findViewById(checkedId)).isChecked()){ if(group == myGroup2){ myGroup3.clearCheck(); } else if(group == myGroup3){ myGroup2.clearCheck(); } // And your switch for whatever you want to happen based on the // selected button goes here } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload