Android Studio – Android RadioButton Example




In this tutorial we will learn How to use RadioButton in Android Using Android Studio.

Generally we use RadioButtons when we want to choose from a list of items. For Example we want to give the option to the user to select his/her favorite animal, in this case we can use RadioButtons to give those options.

So lets create a project.

Step 1  – Create new Android project

Step 2 – Add three RadioButton in the main activity. Also Add a button to the main activity as shown in the picture below.

Android RadioButton Basics With design
Android RadioButton Basics With design

layout/activity_main.xml

 

 

Step 4 – Finally write the following code in MainActivity.java file

com/example/programmingknowledge/thefirstapp/MainActivity.java

 

OUTPUT:

Android RadioButton Basics With Example
Android RadioButton Basics With Example

Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com


  • java.lang.NullPointerException: Attempt to invoke virtual method ‘int android.widget.RadioGroup.getCheckedRadioButtonId()’ on a null object reference