You are on page 1of 2

XML File: Java File:

<?xml version="1.0" encoding="utf-8"?> package com.example.myapplication;


<LinearLayout
xmlns:android="http://schemas. import androidx.appcompat.app.AppCompatActivity;
android.com/apk/res/android"
xmlns:app="http://schemas import android.annotation.SuppressLint;
.android.com/apk/res-auto" import android.os.Bundle;
xmlns:tools="http://schemas.android.com/ import android.view.View;
tools" import android.widget.Button;
android:layout_width="match_parent" import android.widget.RadioButton;
android:layout_height="match_parent" import android.widget.Toast;
tools:context=".MainActivity"
android:orientation="vertical"> public class MainActivity extends AppCompatActivity {
<TextView Button b1;
android:layout_width="wrap_content" RadioButton a;
android:layout_height="wrap_content" RadioButton b;
android:text="Single Radio Button"/> RadioButton c;
<RadioButton RadioButton d;
android:layout_width="wrap_content"
android:layout_height="wrap_content" @SuppressLint("MissingInflatedId")
android:text="Radio1" @Override
android:id="@+id/a"/> protected void onCreate(Bundle savedInstanceState) {
<RadioButton super.onCreate(savedInstanceState);
android:layout_width="wrap_content" setContentView(R.layout.activity_main);
android:layout_height="wrap_content" b1=(Button) findViewById(R.id.b1);
android:text="Radio2" a=(RadioButton) findViewById(R.id.a);
android:id="@+id/b"/> b=(RadioButton) findViewById(R.id.b);
<TextView c=(RadioButton) findViewById(R.id.c);
android:layout_width="wrap_content" d=(RadioButton) findViewById(R.id.d);
android:layout_height="wrap_content" }
android:text="Radio Button inside public void show(View view)
RadioGroup"/> {
<RadioGroup String s="You Selected:";
android:layout_width="wrap_content" if(a.isChecked()==true)
android:layout_height="wrap_content"> {
<RadioButton s+="Radio1";
android:layout_width="wrap_content" }
if(b.isChecked()==true)
android:layout_height="wrap_content" {
android:text="Male" s+=",Radio2";
android:id="@+id/c"/> }
<RadioButton if(c.isChecked()==true)
android:layout_width="wrap_content" {
android:layout_height="wrap_content" s+=",Male";
android:text="Female" }
android:id="@+id/d"/> if(d.isChecked()==true)
</RadioGroup> {
<Button s+=",Female";
android:layout_width="wrap_content" }
android:layout_height="wrap_content"
android:text="Show" Toast.makeText(getApplicationContext(),s,Toast.LENGTH_LONG).sh
android:onClick="show" ow();
android:id="@+id/b1"/> }
</LinearLayout> }
Output:

You might also like