If you not understand this lecture Radio button in android studio.You should also read my previous lectures. Checkbox creation using android studio and Button and its click events in android . After reading these lecture you will also able to create android Radio button of your app.


Radio button allow to user to choice one option at  a same time to set predefined options. Radio button are arrange as group two or more and displayed on screen a list of circular holes that can contain white space .Radio button is a  two-states button that can be either checked or unchecked. When the radio button is checked, you can click it to unchecked it.


In this lecture well we describe how can create Radio button in android.We will also describe Radio button and its description.what is Radio button. why we can use it .After Reading this lecture you will understand Radio button in android And i hope you will create Radio button of your application.

Description of  android radio button

In this lecture we will describe how can create a android Radio button . If you can use  android Radio button . you can select one option at a time. Radio button is a  two-states button that can be either checked or unchecked. When the radio button is checked, you can click it to unchecked it. Radio button  works with RadioGroupe. Radio group can hold multiple Radio Buttons.Once a radio button is checked by user it cannot be unchecked again by pressing the same button. In this application we describe how can create a Radio button and how can handle click events on Radio button.For more detail about android Radio button u click on Radio button using android. First of all you will create a new project in android studio.  Every project contain two file first is java class file and second is layout XML file your first step is open a layout XML file and add a text view and set height and width and we also  add a RadioGroupe . All  the radio button are add within  RadioGroupe. So you will find out the value folder expand this value folder and click on string XML file and add  string  resource in string.XML file.Now i open a string. XML file and paste that code  into string resource file.

XML Layout 

So we add Radio Group into this layout and set height and width and inside the Radio group we will  add three Radio button and  also add Edit text. purpose of add a Edit text is that.when user select a any one Radio option . Message show which option is selected.

Different property that are used in layout.xml file  explain here

  • warp_content   warp_content means height and width similar to the text that are entered.
  • Match_parent   means height and width similar to parent.
  • Radio button     Radio button allow to user to choice one option at  a same time to set predefined options
  • Edit text              show massage  which option select.

In this example we are going to create a simple UI that includes only (android Radio button ) with Different attributes.And paste the following code android Radio button using android into layout .XML file.

Now you may open the Graphical layout editor to preview the User Interface you created of Radio button  using android.

Alt Tag android Radio button


Main Activity

In main activity we will use a  switch case in which get id of each Radio button.It can divide into two alternative if and else condition when user can select a option then if condition will invoke.when user can not select a option then else condition will invoke.three cases we will use and every case will divide  into two alternative if and else.

Code that are placed in java class file of Radio button  using android

Run the application of Radio button using android

Alt tag android Radio button 1

Now when you can click first option then output show in below pic

Alt Tag output android radio button

Now when you can click  Last option then output show in below pic

Alt Tag output android radio button2

“Thank you”  for reading this lecture, Hope you got the idea.

  • charsi

    I am getting the following error:

    E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.cmmalli.helloworld, PID: 3823
    java.lang.IllegalStateException: Could not find method onRadioButtonClicked(View) in a parent or ancestor Context for android:onClick attribute defined on view class with id ‘radioButton15’
    at android.view.View.performClick(
    at android.widget.CompoundButton.performClick(
    at android.view.View$
    at android.os.Handler.handleCallback(
    at android.os.Handler.dispatchMessage(
    at android.os.Looper.loop(
    at java.lang.reflect.Method.invoke(Native Method)
    Application terminated.

    My Code is:

    public class MainActivity extends AppCompatActivity {

    EditText TotalBilleditText;
    EditText TipeditText;
    TextView textView5;
    Button btnAdd;
    RadioGroup rg;
    RadioButton radioButton15;

    double num1, num2, sum;
    double tax15, tax18, tax20, tax25;
    * ATTENTION: This was auto-generated to implement the App Indexing API.
    * See for more information.
    private GoogleApiClient client;

    protected void onCreate(Bundle savedInstanceState) {
    textView5 = (TextView)findViewById(;

    public void selectTip(View view) {
    boolean checked = ((RadioButton) view).isChecked();
    switch (view.getId()) {
    if (checked) {
    textView5.setText(“you select apple”);

    } else {



    Can you please guide me where am I going wrong? Thank you!