0% found this document useful (0 votes)
35 views6 pages

Android Toast and Order App Code

The document contains two Android application implementations using XML and Java. The first part demonstrates a simple layout with a button that shows a toast message when clicked. The second part includes a layout with checkboxes for food items and a button that displays a summary of selected items and their total price in a toast message when clicked.

Uploaded by

itzinnovator01
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)
35 views6 pages

Android Toast and Order App Code

The document contains two Android application implementations using XML and Java. The first part demonstrates a simple layout with a button that shows a toast message when clicked. The second part includes a layout with checkboxes for food items and a button that displays a summary of selected items and their total price in a toast message when clicked.

Uploaded by

itzinnovator01
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

Practical 15

Q1.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<LinearLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="16dp">

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Practical 15 - Toast"
android:textStyle="bold"
android:layout_marginBottom="20dp"
android:textSize="20sp"/>

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Content" />
</LinearLayout>
</[Link]>
[Link]
package [Link].prc15;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

Button showToastButton = findViewById([Link]);


[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link], "Message for you: You have got mail!",
Toast.LENGTH_LONG).show();
}
});
}
}
Q2.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<LinearLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="16dp">

<CheckBox
android:id="@+id/checkBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="17sp"
android:text="Pizza" />

<CheckBox
android:id="@+id/checkBox2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="17sp"
android:text="Dal Bhatti" />

<CheckBox
android:id="@+id/checkBox3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="17sp"
android:text="Civet Coffee" />

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Order"
android:layout_marginTop="20dp" />
</LinearLayout>
</[Link]>

[Link]
package [Link].prc15;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

CheckBox pizzaCheckBox = findViewById([Link]);


CheckBox coffeeCheckBox = findViewById([Link].checkBox2);
CheckBox burgerCheckBox = findViewById([Link].checkBox3);
Button orderButton = findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View v) {
StringBuilder orderSummary = new StringBuilder("Selected Items:\n");
int total = 0;

if ([Link]()) {
[Link]("Pizza: ₹300\n");
total += 300;
}
if ([Link]()) {
[Link]("Dal Bhatti: ₹200\n");
total += 200;
}
if ([Link]()) {
[Link]("Civer Coffee: ₹300\n");
total += 300;
}

[Link]("Total: ").append(total).append("₹");
[Link]([Link], [Link](),
Toast.LENGTH_LONG).show();
}
});
}
}

You might also like