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

Practical 15.2

The document contains an Android application code with an XML layout and Java activity for a food ordering interface. It features checkboxes for selecting items like Pizza, Coffee, and Burger, along with a button to place the order. When the order button is clicked, it displays a summary of selected items and their total cost using a Toast message.

Uploaded by

Pruthesh Upadhye
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)
4 views3 pages

Practical 15.2

The document contains an Android application code with an XML layout and Java activity for a food ordering interface. It features checkboxes for selecting items like Pizza, Coffee, and Burger, along with a button to place the order. When the order button is clicked, it displays a summary of selected items and their total cost using a Toast message.

Uploaded by

Pruthesh Upadhye
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

15.2 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:gravity="center"
android:padding="20dp">

<CheckBox
android:id="@+id/chkPizza"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pizza" />

<CheckBox
android:id="@+id/chkCoffee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coffee" />

<CheckBox
android:id="@+id/chkBurger"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Burger" />

<Button
android:id="@+id/btnOrder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ORDER"
android:layout_marginTop="20dp"/>
</LinearLayout>

15.2 MainActivity.java

package com.example.practical7;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private CheckBox chkPizza, chkCoffee, chkBurger;


private Button btnOrder;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize UI components
chkPizza = findViewById(R.id.chkPizza);
chkCoffee = findViewById(R.id.chkCoffee);
chkBurger = findViewById(R.id.chkBurger);
btnOrder = findViewById(R.id.btnOrder);

// Set click listener for button


btnOrder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showOrderSummary();
}
});
}

private void showOrderSummary() {


StringBuilder orderSummary = new StringBuilder("Selected Items:\n");
int totalAmount = 0;

if (chkPizza.isChecked()) {
orderSummary.append("Pizza 150Rs\n");
totalAmount += 150;
}
if (chkCoffee.isChecked()) {
orderSummary.append("Coffee 50Rs\n");
totalAmount += 50;
}
if (chkBurger.isChecked()) {
orderSummary.append("Burger 120Rs\n");
totalAmount += 120;
}

if (totalAmount > 0) {
orderSummary.append("Total: ").append(totalAmount).append("Rs");
Toast.makeText(getApplicationContext(), orderSummary.toString(),
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "No items selected!",
Toast.LENGTH_SHORT).show();
}
}
}
15.2 Output

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