--ADVERTISEMENT--

In this tutorial, I will show how to use android radio buttons in android application. A RadioGroup is used for a set of radio buttons and radio buttons allow the users to select one option among many options. Normally, both RadioGroup and radio buttons are used together in android.

Related:
Android Layouts Tutorial
Android ListView Example
How to Implement Ripple Effect in Android

Android Example: How to use Android Radio Button


Create a new Android Project
Let’s start by creating a new android project with following information to use android radio buttons.

Application Name: Android Radio Button Example
Company Domain: viralandroid.com
Package Name: com.viralandroid.androidradiobuttonexample
Minimum SDK: Android 2.2 (API 8 Froyo)

XML Layout File

Following is the xml layout file with RadioGroup and RadioButton.
res/layout/activity_main.xml

Java Activity File

In java activity file we control the radio button by onClick event. Here, I have placed a message in toast that displays when you select one option from the set.
src/MainActivity.java

Default content of strings.xml file
res/values/strings.xml

Finally, you have finished all. Now, run your application and choose one option.

Output:

Android Radio Button Example

Post a Comment

Powered by Blogger.