0% found this document useful (0 votes)
11 views5 pages

Practical 15

The document contains two exercises related to mobile application development. The first exercise involves creating a program to display a toast message when a button is clicked, while the second exercise requires displaying three checkboxes and a button that shows a toast with selected items and their total prices. Both exercises include XML and Java code examples for implementation.

Uploaded by

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

Practical 15

The document contains two exercises related to mobile application development. The first exercise involves creating a program to display a toast message when a button is clicked, while the second exercise requires displaying three checkboxes and a button that shows a toast with selected items and their total prices. Both exercises include XML and Java code examples for implementation.

Uploaded by

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

Subject :- Mobile Application Development Subject Code :- 22617

Name :- Shivam Sainath Korpakwad Batch :- CO 6 IA Roll No. 24

Exercise :-

1). Write a program to display following toast message.

Code :-
Xml Code :-
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Java Code :-
package com.example.javaapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class Pr15_ToastMessage extends AppCompatActivity
{
private Button TButton;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pr15_toast_message);
TButton=findViewById(R.id.ToastButton);
TButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
Toast.makeText(getApplicationContext(),"Message For You:\n You have Got
mail",Toast.LENGTH_LONG).show();
}
});
}
}

Output :-
2). Write a program 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 prices.
Code :-
Xml Code :-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
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>
Java Code :-
package com.example.javaapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
public class Pr15_CheckBoxOrder extends AppCompatActivity
{
CheckBox pizza,coffe,burger;
Button buttonOrder;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pr15_check_box_order);
addListenerOnButtonClick();
}
public void addListenerOnButtonClick()
{
pizza=findViewById(R.id.checkBox);
coffe=findViewById(R.id.checkBox2);
burger=findViewById(R.id.checkBox3);
buttonOrder=findViewById(R.id.button);
buttonOrder.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
int totalamount=0;
StringBuilder result=new StringBuilder();
result.append("Selected Items:");
if(pizza.isChecked())
{
result.append("\nPizza 100Rs");
totalamount+=100;
}
if(coffe.isChecked())
{
result.append("\nCoffe 50Rs");
}
if(burger.isChecked())
{
result.append("\nBurger 120Rs");
totalamount+=120;
}
result.append("\nTotal: "+totalamount+"Rs");
Toast.makeText(getApplicationContext(), result.toString(), Toast.LENGTH_LONG).show();
}
});
}
}
Output :-

You might also like