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

Android Toast & Checkbox Demo

This document contains code for two Android programming exercises. The first displays a toast message when a button is clicked. The second displays three checkboxes for pizza, coffee, and burger and calculates the total price when an "Order" button is clicked by checking which checkboxes are selected. The code includes XML layout files and Java activity classes to display the user interfaces and handle button click events. When the order button is clicked, a toast message is displayed listing the selected items and their individual and total prices.

Uploaded by

Ganesh Ekambe
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)
345 views6 pages

Android Toast & Checkbox Demo

This document contains code for two Android programming exercises. The first displays a toast message when a button is clicked. The second displays three checkboxes for pizza, coffee, and burger and calculates the total price when an "Order" button is clicked by checking which checkboxes are selected. The code includes XML layout files and Java activity classes to display the user interfaces and handle button click events. When the order button is clicked, a toast message is displayed listing the selected items and their individual and total prices.

Uploaded by

Ganesh Ekambe
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

Name: Mohan Lobhaji Yedatkar

SUB: MAD
Practical No: 15
[Link]: 58
X. Exercise:
1. Write a Program to display following toast Message
 activity_pr15_toast_message.xml
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Pr15_ToastMessage">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/TextViewMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello world, Toast Example"
android:textSize="20dp"
tools:ignore="MissingConstraints" />

<Button
android:id="@+id/ToastButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:text="Show Toast"
android:textStyle="bold"
tools:ignore="MissingConstraints,TextSizeCheck" />
</LinearLayout>

</[Link]>
 Pr15_ToastMessage.java
package [Link];

import [Link];

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

public class Pr15_ToastMessage extends AppCompatActivity {


private Button TButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_pr15_toast_message);
TButton=findViewById([Link]);

[Link](new [Link](){
@Override
public void onClick(View view) {
[Link](getApplicationContext(),"Message For You:\n You have
Got mail",Toast.LENGTH_LONG).show();
}
});

}
}
OUTPUT
2. Write a program to display three checkboxes and one buttons named “Order “ as
shown below. Once you click on button it should toast different selected checkboxes
along with items individual and total price.
 activity_pr15_check_box_order.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Pr15_CheckBoxOrder">

<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="144dp"
android:layout_marginTop="68dp"
android:text="Pizza"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="144dp"
android:layout_marginTop="28dp"
android:text="Coffee"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox" />

<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="144dp"
android:layout_marginTop="28dp"
android:text="Burger"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox2" />

<Button

android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="144dp"
android:layout_marginTop="184dp"
android:text="Order"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox3" />
</LinearLayout>

 Pr15_CheckBoxOrder.java
package [Link];

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

public class Pr15_CheckBoxOrder extends AppCompatActivity {


CheckBox pizza,coffe,burger;
Button buttonOrder;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_pr15_check_box_order);
addListenerOnButtonClick();
}
public void addListenerOnButtonClick(){

pizza=findViewById([Link]);
coffe=findViewById([Link].checkBox2);
burger=findViewById([Link].checkBox3);
buttonOrder=findViewById([Link]);

[Link](new [Link](){

@Override
public void onClick(View view) {
int totalamount=0;
StringBuilder result=new StringBuilder();
[Link]("Selected Items:");
if([Link]()){

[Link]("\nPizza 100Rs");
totalamount+=100;
}
if([Link]()){
[Link]("\nCoffe 50Rs");
totalamount+=50;
}
if([Link]()){
[Link]("\nBurger 120Rs");
totalamount+=120;
}
[Link]("\nTotal: "+totalamount+"Rs");
[Link](getApplicationContext(), [Link](), Toast.LENGTH_LONG).show();

});
}
}

OUTPUT

You might also like