How to check if a radiobutton is checked in a radiogroup in Android?

后端 未结 10 2133

I need to set validation that user must fill / select all details in a page. If any fields are empty wanna show Toast message to fill. Now I need set validation

10条回答
  •  独厮守ぢ
    2020-12-04 13:24

    If you want to check on just one RadioButton you can use the isChecked function

    if(radioButton.isChecked())
    {
      // is checked    
    }
    else
    {
      // not checked
    }
    

    and if you have a RadioGroup you can use

    if (radioGroup.getCheckedRadioButtonId() == -1)
    {
      // no radio buttons are checked
    }
    else
    {
      // one of the radio buttons is checked
    }
    

提交回复
热议问题