Show/Add title to RadioGroup Radio Button in android

How to create RadioGroup with title heading just above radio button inside RadioGroup in android app.

By default whenever android developer creates RadioGroup then there are no title available for it, but title can be easily addable via TextView tag. All we have to do in create TextView inside radio group. Title helps the user to understand about RadioGroup selection menu so they can know what they are selecting. So here is the complete step by step tutorial for Show/Add title to RadioGroup Radio Button in android.

android-project-download-code-button

How to Show/Add title to RadioGroup Radio Button in android.

Code for MainActivity.java file.

package com.addtitleradiogroup_android_examples.com;
import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.addtitleradiogroup_android_examples.com.MainActivity" >

 <RadioGroup
 android:id="@+id/radiogroup1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:background="#fceeab"
 android:padding="20dp"
 
 >
 
 <TextView 
 android:id="@+id/textview1"
 android:layout_height="wrap_content"
 android:layout_width="wrap_content"
 android:gravity="center"
 android:text="Select Any Subject"
 android:textSize="20dp"/>
 
 <RadioButton
 android:id="@+id/radioButton1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:text="Android" />

 <RadioButton
 android:id="@+id/radioButton2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignLeft="@+id/radioButton1"
 android:layout_below="@+id/radioButton1"
 android:text="PHP" />

 <RadioButton
 android:id="@+id/radioButton3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignLeft="@+id/radioButton2"
 android:layout_below="@+id/radioButton2"
 android:text="Blogger" />

 </RadioGroup>
</RelativeLayout>

Screenshot:

Show/Add title to RadioGroup Radio Button in android

Click here to download Show/Add title to RadioGroup Radio Button in android project with source code.