How To Check Which Radio-button Is Selected In Android

In Android Radio-Button Is Used When We Want To Select Any One Item at a time . It  is a circle representing choices in a common option list form in a graphical user interface that typically only allows for one of the options to be selected.

Radio-button

  • We can create this  instance by declaring it inside a layout(XML file) or by instantiating it programmatically(Java Class) We Will See The Example In Bellow.

Step 1: Create a new project and name it what you want to give

  • Select File -> New -> New Project. Fill the forms and click “Finish” button.

Step 2: Open res -> layout -> xml (or) activity_main.xml and add following code. Here we will create a Radio-Button in Radio-Group in between Relative Layout.

Step 3: Open app -> java -> package and open MainActivity.java and add the following code. Here we will display in toast which Radio-Button is checked.

Output :

Now run the app in Emulator and click on the button. You will see which Radio-Button is checked and display it name in toast.

Radio-button

Leave a Reply

Your email address will not be published. Required fields are marked *