0% found this document useful (0 votes)
7 views4 pages

Aim: Create An Android App That Includes Four Radio Buttons Activitymain - XML

Uploaded by

owaisscb127
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Aim: Create An Android App That Includes Four Radio Buttons Activitymain - XML

Uploaded by

owaisscb127
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Owais shaikh

TYCS B, 8881

Aim: Create an Android app that includes four radio buttons


Activitymain.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RadioGroup android:id="@+id/radiogroup"
android:layout_width="match_parent"
android:layout_height="255dp"
android:layout_marginLeft="30dp">
<RadioButton
android:id="@+id/radioButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Excellant" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Good" />
<RadioButton
android:id="@+id/radioButton3"
Owais shaikh
TYCS B, 8881

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Okay" />
<RadioButton
android:id="@+id/radioButton4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Poor" />
</RadioGroup>
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_marginTop="250dp"
android:layout_marginLeft="150dp"
/>
</RelativeLayout>

MainActivity.java
package com.example.androidpracticals;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
Owais shaikh
TYCS B, 8881

import androidx.appcompat.app.AppCompatActivity; public


class MainActivity extends AppCompatActivity {
// These are the global variables
RadioGroup radioGroup;
RadioButton selectedRadioButton;
Button buttonSubmit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// layout instances
buttonSubmit = (Button) findViewById(R.id.button3); radioGroup =
(RadioGroup) findViewById(R.id.radiogroup);
buttonSubmit.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

// get the selected RadioButton of the group

selectedRadioButton =
(RadioButton)findViewById(radioGroup.getCheckedRadioButtonId());
//get RadioButton text
String yourVote = selectedRadioButton.getText().toString();
// display it as Toast to the user
Toast.makeText(MainActivity.this, "Selected Radio Button is:" + yourVote ,
Toast.LENGTH_LONG).show();
} }); }}
Owais shaikh
TYCS B, 8881

You might also like