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

Prac 11 (Mad)

The document contains XML and Java code for an Android application that displays five checkboxes for different cuisines and shows a toast message with the selected options. The layout includes a heading, subheading, and a submit button. The Java code handles the checkbox selections and displays the selected cuisines or a message if none are selected when the button is clicked.

Uploaded by

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

Prac 11 (Mad)

The document contains XML and Java code for an Android application that displays five checkboxes for different cuisines and shows a toast message with the selected options. The layout includes a heading, subheading, and a submit button. The Java code handles the checkbox selections and displays the selected cuisines or a message if none are selected when the button is clicked.

Uploaded by

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

PRACTICAL 11

Q.W.A.C to show 5 checkboxes and toast selected checkboxes


Xml code:
<?xml version="1.0" encoding="utf-8"?> android:layout_marginTop="16dp"/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/a <CheckBox
ndroid" android:id="@+id/checkBox2"
xmlns:app="http://schemas.android.com/apk/res- android:layout_width="match_parent"
auto" android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools" android:text="Chinese"
android:layout_width="match_parent" android:textSize="16sp"
android:layout_height="match_parent" android:textColor="#4CAF50"
android:background="#ffffff" android:layout_marginTop="16dp"/>
android:orientation="vertical"
android:padding="16dp"> <CheckBox
android:id="@+id/checkBox3"
<!-- Attractive Heading TextView --> android:layout_width="match_parent"
<TextView android:layout_height="wrap_content"
android:id="@+id/textViewHeading" android:text="Indian"
android:layout_width="match_parent" android:textSize="16sp"
android:layout_height="wrap_content" android:textColor="#4CAF50"
android:text="Explore Delicious Cuisines!" android:layout_marginTop="16dp"/>
android:textSize="28sp"
android:textColor="#FF5722" <CheckBox
android:layout_marginTop="30dp" android:id="@+id/checkBox4"
android:gravity="center" android:layout_width="match_parent"
android:textStyle="bold"/> android:layout_height="wrap_content"
android:text="Mexican"
<!-- Subheading TextView: Select Cuisines --> android:textSize="16sp"
<TextView android:textColor="#4CAF50"
android:id="@+id/textView" android:layout_marginTop="16dp"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
<CheckBox
android:text="Choose your favorite cuisines:"
android:id="@+id/checkBox5"
android:textSize="20sp"
android:layout_width="match_parent"
android:textColor="#4CAF50"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Japanese"
android:gravity="center"/>
android:textSize="16sp"
android:textColor="#4CAF50"
<!-- Cuisines Checkboxes -->
android:layout_marginTop="16dp"/>
<CheckBox
android:id="@+id/checkBox"
android:layout_width="match_parent" <!-- Submit Button -->
android:layout_height="wrap_content" <Button
android:text="Italian" android:id="@+id/button"
android:textSize="16sp" android:layout_width="match_parent"
android:textColor="#4CAF50" android:layout_height="wrap_content"
android:text="Submit"
android:textSize="18sp"
android:textColor="#ffffff"
android:layout_marginTop="32dp”
android:background="#FF5722"
android:onClick="Check"/>

</LinearLayout>
Java code:

package com.example.practical_11; // Checking the selection of each checkbox


import android.os.Bundle; if (italian.isChecked()) {
import android.view.View; msg = msg + " [Italian]";
import android.widget.CheckBox; }
import android.widget.Toast; if (chinese.isChecked()) {
msg = msg + ", [Chinese]";
import }
androidx.appcompat.app.AppCompatActivity; if (indian.isChecked()) {
msg = msg + ", [Indian]";
public class MainActivity extends }
AppCompatActivity { if (mexican.isChecked()) {
CheckBox italian, chinese, indian, mexican, msg = msg + ", [Mexican]";
japanese; }
if (japanese.isChecked()) {
@Override msg = msg + ", [Japanese]";
protected void onCreate(Bundle }
savedInstanceState) {
super.onCreate(savedInstanceState); // Displaying the selected cuisines using
setContentView(R.layout.activity_main); Toast
if (msg.equals("Selected Cuisines are:")) {
// Binding the checkboxes with the Toast.makeText(this, "No cuisine
corresponding views selected", Toast.LENGTH_LONG).show();
italian = findViewById(R.id.checkBox); } else {
chinese = findViewById(R.id.checkBox2); Toast.makeText(this, msg,
indian = findViewById(R.id.checkBox3); Toast.LENGTH_LONG).show();
mexican = findViewById(R.id.checkBox4); }
japanese = findViewById(R.id.checkBox5);
} // Clearing the selections after showing the
message
// Method to handle the button click italian.setChecked(false);
public void Check(View v) { chinese.setChecked(false);
String msg = "Selected Cuisines are:"; indian.setChecked(false);
mexican.setChecked(false);
japanese.setChecked(false);
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy