0

Having two RadioButtons and button send.
When I click on the send button the 2 RadioButtons are checked.

How to avoid this? enter image description here

3 Answers3

1

If you want only one RadioButton to be checked at once, keep them inside a RadioGroup.

Nabin Bhandari
  • 15,949
  • 6
  • 45
  • 59
1

You need to group the radio buttons so inside the xml add the radio buttons inside this tag:

<RadioGroup> .....</RadioGroup>

then in your activity do this:

RadioGroup radioGroup = (RadioGroup) findViewById(R.id.myRadioGroup); //declare the radiogroup


radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
      @Override

        public void onCheckedChanged(RadioGroup group, int checkedId) {

            // find which radio button is selected

            if(checkedId == R.id.radiobtn1) {

                //code here
            } else if(checkedId == R.id.radiobtn2) {

                //code here

            } else {

               //code here
            }
        }
    });
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
0

Just Put your RadioButtons inside RadioGroup