Android radio button is used to select a option out of available options. Generally, we see these radio buttons in reservation forms and several other forms.

In this tutorial on android radio button example we will see a radio button for selecting a class out of first class, second class, third class. And then click on button to select the option and also to get selected output as toast.

In this tutorial i will show a radio-button using which user can select a class i.e., only one button can be selected at a time, if we select second time first button will be disabled automatically.If you want to select both the options you may refer my previous tutorial on  android checkbox example from link below

http://www.androidcoding.in/check-box/

 

Here i am assigning the selected value of the radio button stored in a string & toast is given as output.

 

MainActivity.java

Using a radioListener() we will be selecting the option based on the user selection.And there after displaying a toast of the selected value on the screen.

 

In layout add radio-group under which radio buttons are added and according to your requirement take radio buttons and also a normal button to submit the value.

Android Radio group will help you to group up all the radio buttons so that it will be much easier when you select an option of all because when you select an option all the remaining options gets disabled automatically if you have not declared them under radio group then you may not be able to handle this disable functionality so as to choose only one out of all.

 

activity_main.xml

AndroidManifest.xml

 

Output :

 

radio-button1

 

radio-button2

 

If you have any query regarding tutorial let me know below in comment section.

Like and share this tutorial if you like it and for more tutorial subscribe us.

Show Buttons
Hide Buttons
Read previous post:
Android Tutorial on Dialog-Box

Close