Note that there are some explanatory texts on larger screens.

plurals
  1. POsetOnCheckedChangeListener of RadioGroup is called twice after calling clearCheck() on RadioGroup
    primarykey
    data
    text
    <p>I have a RadioGroup with some radio buttons. I am using this method <strong>rGroup.clearCheck();</strong> to clear the checked itme in RadioGroup. Problem is that RadioGroup.setOnCheckedChangeListener is getting called twice after I use this method clearCheck(). I am facing problem is this method is called twice.</p> <pre><code>public class MainActivity extends Activity { private RadioGroup rGroup; private String str; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); rGroup = (RadioGroup) findViewById(R.id.radioGroup1); rGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // TODO Auto-generated method stub if (checkedId == R.id.radio0) { str = "Radio0"; } else if (checkedId == R.id.radio1) { str = "Radio1"; } else if (checkedId == R.id.radio2) { str = "Radio2"; } } }); } public void clearRadio(View v) { rGroup.clearCheck(); } } </code></pre> <p>xml file</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" &gt; &lt;RadioGroup android:id="@+id/radioGroup1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/textView1" android:layout_marginLeft="48dp" android:layout_marginTop="58dp" &gt; &lt;RadioButton android:id="@+id/radio0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="RadioButton1" /&gt; &lt;RadioButton android:id="@+id/radio1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="RadioButton2" /&gt; &lt;RadioButton android:id="@+id/radio2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="RadioButton3" /&gt; &lt;/RadioGroup&gt; &lt;Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/radioGroup1" android:onClick="clearRadio" android:text="Clear" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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