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

Develop An Application To Show F

The document provides code for an Android application featuring five checkboxes and a button to display selected options. The XML layout defines the user interface, while the Java code handles the logic for displaying selected checkboxes in a TextView when the button is clicked. The application uses Toast notifications to show the selected options to the user.

Uploaded by

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

Develop An Application To Show F

The document provides code for an Android application featuring five checkboxes and a button to display selected options. The XML layout defines the user interface, while the Java code handles the logic for displaying selected checkboxes in a TextView when the button is clicked. The application uses Toast notifications to show the selected options to the user.

Uploaded by

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

6. Develop an application to show five checkboxes and toast selected checkboxes.

Xml Code ( activity_main.xml )

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:gravity="center">

<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1"
android:textSize="16sp" />

<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 2"
android:textSize="16sp"
android:layout_marginTop="8dp" />

<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 3"
android:textSize="16sp"
android:layout_marginTop="8dp" />

<CheckBox
android:id="@+id/checkBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 4"
android:textSize="16sp"
android:layout_marginTop="8dp" />

<CheckBox
android:id="@+id/checkBox5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 5"
android:textSize="16sp"
android:layout_marginTop="8dp" />

<Button
android:id="@+id/submitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Selected"
android:layout_marginTop="16dp" />

<TextView
android:layout_marginTop="25dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:textSize="15dp"/>

</LinearLayout>

Java Code ( MainActivity.java )

package com.example.q6;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


CheckBox checkBox1, checkBox2, checkBox3, checkBox4, checkBox5;
Button submitButton;
TextView textView;

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

checkBox1 = findViewById(R.id.checkBox1);
checkBox2 = findViewById(R.id.checkBox2);
checkBox3 = findViewById(R.id.checkBox3);
checkBox4 = findViewById(R.id.checkBox4);
checkBox5 = findViewById(R.id.checkBox5);
submitButton = findViewById(R.id.submitButton);
textView = findViewById(R.id.textView);

submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String result= "";

if (checkBox1.isChecked())
result += checkBox1.getText().toString()+"\n";

if (checkBox2.isChecked())
result += checkBox2.getText().toString()+"\n";

if (checkBox3.isChecked())
result += checkBox3.getText().toString()+"\n";

if (checkBox4.isChecked())
result += checkBox4.getText().toString()+"\n";

if (checkBox5.isChecked())
result += checkBox5.getText().toString()+"\n";

textView.setText("Selected Checkbox \n" + result);


}
});
}
}

You might also like