Articles → Android → Radiobutton In Android
Radiobutton In Android
What Is Radiobutton?
Radiobutton Groups
Click to Enlarge
Example
- Create a UI with radio button group, 2 radio buttons (male and female).
Click to Enlarge
- On each radio button, add an onclick method.
- Add RadioButtonClicked event in Java file
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
Click to Enlarge