Android 4c
Android 4c
TYCS B, 8881
Aim: Create an Android app that includes checkboxes and Radio buttons.
activity_main.xml
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>
MainActivity.java
package com.example.myapplication;
import android.os.Bundle;
import android.view.View;
import android.widget.Button; import
android.widget.CheckBox; import
android.widget.RadioButton; import
android.widget.RadioGroup; import
android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity; public
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Submit Button
buttonSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Get the selected RadioButton selectedRadioButton
= (RadioButton)
findViewById(radioGroup.getCheckedRadioButtonId());
// get RadioButton text
String yourVote = selectedRadioButton.getText().toString(); String
checkBoxChoices = "";
if (check.isChecked()) {
checkBoxChoices += check.getText().toString() + "\tYES";
} else {
checkBoxChoices += check.getText().toString() + "\tNO";
}
if (check2.isChecked()) {
checkBoxChoices += check2.getText().toString() + "\tYES";
} else {
checkBoxChoices += check2.getText().toString() + "\tNO";
}
if (check3.isChecked()) {
checkBoxChoices += check3.getText().toString() + "\tYES";
} else {
checkBoxChoices += check3.getText().toString() + "\tNO";
}
if (check4.isChecked()) {
checkBoxChoices += check4.getText().toString() + "\tYES";
} else {
checkBoxChoices += check4.getText().toString() + "\tNO";
}
});}}
Owais Shaikh
TYCS B, 8881