android radio button
Radio Button in Android :

Radio buttons enable users to select one item from a list of available choices. This example shows a way to use radio buttons in your android application.

Solution Stuff:

For a Radio button implementation in android, you can use directly in-build class  “android.widget.RadioButton”.

You just need a drag and drop radio button in xml file (according below figure). Then just write some code for radio button in java class.

android radio buttonNote : This example (Project) is developed in Eclipse Version Kepler, tested on Android 4.4.2 (KitKat Version) and SDK build-tools 22.6.3

Complete Source code :

1. Put this code in main_activity.xml

The RadioButton component represents a two-state button which will be either checked or unchecked. Once a radio button is checked, it can’t be unchecked by tapping on it. Instead, radio buttons are contained inside a RadioGroup component, that contains a group of radio buttons. Checking one radio button in a very radio group unchecks the remainder of the radio buttons in the same group.

 2. Put this java code in MainActivity.class

You can confirm whether or not a radio button is checked by listening to the onCheckedChanged event on of the RadioGroup component. This event is fired whenever a radio button contained within it’s checked or unchecked. to work out the state of a radio button, examine its isChecked() method.

Figure  shows the Toast class displaying a message when a radio button is clicked on the emulator.

android radio button

Android Radio Button Source code Download :

Leave a Reply