Android TutorialsNo Comments

635 views.

Introduction
In this article, we will learn how to use RadioGroup to manage multiple RadioButtons in an Android application. We will check one example to understand how it works in an android application.

What is a RadioGroup?
A RadioGroup is used to create a multiple-exclusion scope for a set of radio buttons. Checking one radio button that belongs to a radio group unchecks any previously checked radio button within the same group. Intially, all of the radio buttons are unchecked.

Pre-requisites
This article is for beginners who have just started developing android apps and want to know the basics. This post may not help you in real-world project development but, is a short working demonstration of RadioGroup and RadioButton control in Android.

RadioGroup in Android
I have developed a very simple example using RadioGroup, I have dragged two TextViews, five RadioButtons and a RadioGroup to my activity_my.xml. Furthermore, some backgroud colouring was added using layout editor in Android Studio.

RadioGroup Example

In the code, setOnCheckedChangeListener listens to onCheckedChanged events on the RadioGroup. A very simple logic is added to identify which RadioButton was selected.

activity_my.xml

MyActivity.java

ddd

Be the first to post a comment.

Add a comment