How to set a radio button in Android

Or you can do it in the XML file :

In the RadioGroup using : android:checkedButton="id_button_to_check"

or in the RadioButton : android:checked="true"


For radioButton use

radio1.setChecked(true);

It does not make sense to have just one RadioButton. If you have more of them you need to uncheck others through

radio2.setChecked(false); ...

If your setting is just on/off use CheckBox.


If you want to do it in code, you can call the check member of RadioGroup:

radioGroup.check(R.id.radioButtonId);

This will check the button you specify and uncheck the others.