0% found this document useful (0 votes)
21 views5 pages

Android App with Checkboxes & Radio Buttons

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)
21 views5 pages

Android App with Checkboxes & Radio Buttons

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

Owais Shaikh

TYCS B, 8881

Aim: Create an Android app that includes checkboxes and Radio buttons.
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout
xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="horizontal">
<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/editTextText"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:ems="10"
android:layout_marginLeft="110dp"
android:text="RATE THIS SECTION" />
<RadioButton
android:id="@+id/radioButton"
android:layout_width="94dp"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:text="Excellant" />
<RadioButton
android:id="@+id/radioButton3"
android:layout_width="87dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:text="Good" />
<RadioButton
android:id="@+id/radioButton4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:text="Average" />
<RadioButton
android:id="@+id/radioButton5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Owais Shaikh
TYCS B, 8881

android:layout_marginRight="20dp"
android:text="Poor" />
</RadioGroup>
<EditText
android:id="@+id/editTextText2"
android:layout_width="500dp"
android:layout_height="50dp"
android:ems="10"
android:text="GIVE YOUR SUGGESTION HERE"
android:layout_marginTop="240dp"
android:layout_marginLeft="80dp"
android:layout_marginRight="60dp"/>

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SUBMIT"
android:layout_marginTop="520dp"
android:layout_marginLeft="150dp"/>

<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I really enjoy this Section"
android:layout_marginTop="300dp"
android:layout_marginLeft="50dp"/>

<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I will prefer this Section else also"
android:layout_marginTop="340dp"
android:layout_marginLeft="50dp"/>

<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I will Like to hear more from you"
android:layout_marginTop="380dp"
android:layout_marginLeft="50dp"/>
Owais Shaikh
TYCS B, 8881

<CheckBox
android:id="@+id/checkBox4"
android:layout_width="280dp"
android:layout_height="60dp"
android:text="I am satisfied with the content and full description"
android:layout_marginTop="420dp"
android:layout_marginLeft="50dp"/>

</RelativeLayout>

[Link]

package [Link];

import [Link];
import [Link];
import [Link]; import
[Link]; import
[Link]; import
[Link]; import
[Link];
import [Link]; public

class MainActivity extends AppCompatActivity {

RadioGroup radioGroup; RadioButton


selectedRadioButton; Button
buttonSubmit;
CheckBox check,check2,check3,check4;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

buttonSubmit = (Button) findViewById([Link]); radioGroup


= (RadioGroup) findViewById([Link]); check=
(CheckBox) findViewById([Link]);
check2 = (CheckBox) findViewById([Link].checkBox2);
check3 = (CheckBox) findViewById([Link].checkBox3);
check4 = (CheckBox) findViewById([Link].checkBox4);
Owais Shaikh
TYCS B, 8881

Submit Button
[Link](new [Link]() {

@Override
public void onClick(View v) {
//Get the selected RadioButton selectedRadioButton
= (RadioButton)
findViewById([Link]());
// get RadioButton text
String yourVote = [Link]().toString(); String

checkBoxChoices = "";

if ([Link]()) {
checkBoxChoices += [Link]().toString() + "\tYES";
} else {
checkBoxChoices += [Link]().toString() + "\tNO";
}

if ([Link]()) {
checkBoxChoices += [Link]().toString() + "\tYES";
} else {
checkBoxChoices += [Link]().toString() + "\tNO";
}

if ([Link]()) {
checkBoxChoices += [Link]().toString() + "\tYES";
} else {
checkBoxChoices += [Link]().toString() + "\tNO";
}

if ([Link]()) {
checkBoxChoices += [Link]().toString() + "\tYES";
} else {
checkBoxChoices += [Link]().toString() + "\tNO";
}

// display it as Toast to the user

[Link]([Link], "Selected Radio Button is:" + yourVote


+ "\n CheckBox Choices: \n " + checkBoxChoices, Toast.LENGTH_LONG).show();

});}}
Owais Shaikh
TYCS B, 8881

You might also like