0% found this document useful (0 votes)
7 views8 pages

Practical No 15

This document outlines a practical exercise for developing a program to implement Custom Toast Alerts in Android applications. It covers the significance of Toast messages, relevant program outcomes, competencies, and includes sample code for creating Toast alerts. Additionally, it provides resources, assessment schemes, and references for further reading.
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)
7 views8 pages

Practical No 15

This document outlines a practical exercise for developing a program to implement Custom Toast Alerts in Android applications. It covers the significance of Toast messages, relevant program outcomes, competencies, and includes sample code for creating Toast alerts. Additionally, it provides resources, assessment schemes, and references for further reading.
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/ 8

Mobile Application Development (22617) Practical No.

15

Practical No. 15: Develop a program to implement Custom Toast Alert.


I. Practical Significance
An Android Toast is a small message displayed on the screen, similar to a tool tip or other
similar popup notification. Android Toast can be used to display information for the short
period of time. A toast contains message to be displayed quickly and disappears after
sometime. It provides simple feedback about an operation in a small popup. A Toast is
displayed on top of the main content of an activity. For example, navigating away from an
email before you send it triggers a "Draft saved" toast to let you know that you can continue
editing later.

II. Relevant Program Outcomes (POs)


PO 2. Discipline knowledge
PO 3. Experiments and practice
PO 4. Engineering tools

III. Competency and Skills


“Create simple Android applications.”
This practical is expected to develop the following skills
1. Able to implement Toast alerts.

IV. Relevant Course Outcome(s)


Use User Interface components for android application development.

V. Practical Outcomes (PrOs)


Develop a program to implement Custom ToastAlert.

VI. Relevant Affective Domain Related Outcome(s)


1. Work collaboratively in team
2. Follow ethical practices

VII. Minimum Theoretical Background


A toast provides simple feedback about an operation in a small popup. It only fills the amount of
space required for the message and the current activity remains visible and interactive. Toasts
automatically disappear after a timeout.
For example, clicking Send button on an email triggers a "Sending message..." toast

Maharashtra State Board of Technical Education 1


Mobile Application Development (22617) Practical No. 15

Following is the example to create a toast.


Toast toast = Toast.makeText(getApplicationContext(),
"This is a message displayed in a Toast",
Toast.LENGTH_SHORT); toast.show();

The Toast.makeText() method is a factory method which creates a Toast object. The method
takes 3 parameters. First the methods needs a Context object which is obtained by calling
getApplicationContext(). Note: The getApplicationContext() method is a method that exists
inside activities, so the above code has to be located in an Activity subclass towork.
The second parameter is the text to be displayed in the Toast. The third parameter is the time
duration the Toast is to be displayed.

VIII. Resources required (Additional)

Sr. Instrument /Object Specification Quantity Remarks


No.
Android enabled 2 GB RAM 1 Data cable is
smartphone / Android mandatory for
1
version supporting emulators
emulator

IX. Practical related Questions


Note: Below given are few sample questions for reference. Teachers must design more
such questions to ensure the achievement of identified CO.
1. List all predefined constants to specify the overall positioning of the Toast. Which method
is used to change the positioning of a Toast message on the screen?
2. List two constants of Toast class.

(Space for answers)


1.
You can use the following constants in the Gravity class to specify the overall position:
TOP
BOTTOM
LEFT
RIGHT
CENTER
CENTER_HORIZONTAL
CENTER_VERTICAL

You can change the positioning on the screen of a Toast message using the setGravity()
method. Here is a Toast setGravity() example:
toast.setGravity(Gravity.CENTER, 0, 0);

Maharashtra State Board of Technical Education 2


Mobile Application Development (22617) Practical No. 15

2.
Constants:
int LENGTH_LONG
Show the view or text notification for a long period of time.

int LENGTH_SHORT
Show the view or text notification for a short period of time.

X. Exercise
(Use blank space provide for answers or attached more pages if needed) 1. Write
a program to display following toast message.

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 price.

Maharashtra State Board of Technical Education 3


Mobile Application Development (22617) Practical No. 15

Answers:
1.
//MainActivity.java

package com.jamiapolytechnic.experiment151;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void showToast(View view)
{
String str = getString(R.string.message);
Toast.makeText(this,str,Toast.LENGTH_LONG).show();
}
}
//Note: Define a string in string.xml file with id as message and value as :
//”Message for you: \n You have got mail”

//=====================================================================
//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">
<TextView android:text="Hello World, Toast Example"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textview" />
<Button
android:layout_width="wrap_content"

Maharashtra State Board of Technical Education 4


Mobile Application Development (22617) Practical No. 15

android:layout_height="wrap_content"
android:text="Show Toast"
android:id="@+id/button"
android:onClick="showToast"/>

</LinearLayout>

//=====================================================================

2.
//MainActivity.java

package com.jamiapolytechnic.experiment15_2;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


CheckBox piz, cof, bur;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
piz = findViewById(R.id.piz);
bur = findViewById(R.id.bur);
cof = findViewById(R.id.cof);
}
public void showDetails(View v) {
String str = "Selected iems:\n";
int piz_price = 200;
int bur_price = 120;
int cof_price = 50;
int total = 0;
if(piz.isChecked()) {
total = total + piz_price;
str = str + "Pizza: " + piz_price + " Rs.\n";
}
if(bur.isChecked()) {
total = total + bur_price;

Maharashtra State Board of Technical Education 5


Mobile Application Development (22617) Practical No. 15

str = str + "Burger: " + bur_price + " Rs.\n";


}
if(cof.isChecked()) {
total = total + cof_price;
str = str + "Coffee: " + cof_price + " Rs.\n";
}
str = str + "Total: " + total + " Rs.";
Toast.makeText(this, str, Toast.LENGTH_LONG).show();
}
}

//=====================================================================
//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" >

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

<CheckBox
android:id="@+id/piz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_gravity="center"
android:text="Pizza" />

<CheckBox
android:id="@+id/cof"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_gravity="center"
android:text="Coffee" />

<CheckBox
android:id="@+id/bur"

Maharashtra State Board of Technical Education 6


Mobile Application Development (22617) Practical No. 15

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_gravity="center"
android:text="Burger" />
</LinearLayout>

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

<Button
android:id="@+id/ord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="100dp"
android:onClick="showDetails"
android:text="Order" />
</LinearLayout>

</LinearLayout>

Maharashtra State Board of Technical Education 7


Mobile Application Development (22617) Practical No. 15

XI. References / Suggestions for further Reading


1. https://www.tutorialspoint.com/android
2. https://stuff.mit.edu
3. https://www.tutorialspoint.com/android/android_advanced_tutorial.pdf
4. https://developer.android.com

XII. Assessment Scheme

Performance indicators Weightage

Process related (10 Marks) 30%

1. Logic Formation 10%


2. Debugging ability 15%
3. Follow ethical practices 5%
Product related (15 Marks) 70%

4. Interactive GUI 20%


5. Answer to Practical related questions 20%
6. Expected Output 20%
7. Timely Submission 10%
Total (25 Marks) 100%

List of students/Team Members


1
2
3
4

Dated signature of
Marks Obtained
Teacher
Process Product Total
Related(10) Related(15) (25)

Maharashtra State Board of Technical Education 8

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