Articles → Android → Radiobutton in android

Radiobutton in android






What is radiobutton?





Radiobutton groups




Picture showing how radiobutton groups put the radiobuttons inside it

Click to Enlarge


Example






Picture showing adding 2 radiobuttons inside the constraint layout

Click to Enlarge





public void RadioButtonClicked(View view) {
  RadioButton radioButton = (RadioButton) view;
  if (radioButton.isChecked()) {
    if (radioButton.getId() == R.id.maleRadioButton)
      Toast.makeText(this, "Male Radio Button Clicked", Toast.LENGTH_LONG).show();
    else if (radioButton.getId() == R.id.femaleRadioButton)
      Toast.makeText(this, "Female Radio Button Clicked", Toast.LENGTH_LONG).show();
  }
}



Output


Picture showing the output of radio buttons in android

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, November 19, 2019

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250