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

Develop An Application To Displ

The document outlines the development of an Android application featuring three checkboxes for selecting food items (Pizza, Coffee, Burger) and a button to place an order. Upon clicking the button, the app displays a toast message with the selected items and the total price. The provided XML and Java code illustrate the layout and functionality of the application.

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)
5 views2 pages

Develop An Application To Displ

The document outlines the development of an Android application featuring three checkboxes for selecting food items (Pizza, Coffee, Burger) and a button to place an order. Upon clicking the button, the app displays a toast message with the selected items and the total price. The provided XML and Java code illustrate the layout and functionality of the application.

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/ 2

12.

Develop an application to display three checkboxes and one button named “Order
“as shown below. Once you click on button it should toast different selected
checkboxes along with items individual and total price.

Xml Code ( activity_main.xml )

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


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

<CheckBox
android:id="@+id/checkbox_pizza"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pizza - 100 Rs" />

<CheckBox
android:id="@+id/checkbox_coffee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coffee - 50 Rs" />

<CheckBox
android:id="@+id/checkbox_burger"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Burger - 120 Rs" />

<Button
android:id="@+id/button_order"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Place Order"
android:layout_marginTop="20dp" />

<TextView
android:id="@+id/text_output"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:layout_marginTop="20dp" />
</LinearLayout>

Java Code ( MainActivity.java )

package com.example.q12;

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 checkboxPizza, checkboxCoffee, checkboxBurger;


Button buttonOrder;
TextView textOutput;

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

checkboxPizza = findViewById(R.id.checkbox_pizza);
checkboxCoffee = findViewById(R.id.checkbox_coffee);
checkboxBurger = findViewById(R.id.checkbox_burger);
buttonOrder = findViewById(R.id.button_order);
textOutput = findViewById(R.id.text_output);

buttonOrder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int totalAmount = 0;
StringBuilder result = new StringBuilder("Selected Items:");

if (checkboxPizza.isChecked()) {
result.append("\nPizza - 100 Rs");
totalAmount += 100;
}

if (checkboxCoffee.isChecked()) {
result.append("\nCoffee - 50 Rs");
totalAmount += 50;
}

if (checkboxBurger.isChecked()) {
result.append("\nBurger - 120 Rs");
totalAmount += 120;
}

result.append("\nTotal: ").append(totalAmount).append(" Rs");

textOutput.setText(result.toString());

Toast.makeText(getApplicationContext(), result.toString(),
Toast.LENGTH_LONG).show();
}
});
}
}

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