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

Using Toast in Android Apps

This document outlines an Android application experiment demonstrating the use of Toast for displaying messages. It includes XML layout code for a button and Java code for the main activity that shows a Toast message when the button is clicked. The example illustrates how to provide simple feedback to users in a mobile application.

Uploaded by

mansinner666
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)
17 views5 pages

Using Toast in Android Apps

This document outlines an Android application experiment demonstrating the use of Toast for displaying messages. It includes XML layout code for a button and Java code for the main activity that shows a Toast message when the button is clicked. The example illustrates how to provide simple feedback to users in a mobile application.

Uploaded by

mansinner666
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

Date: 01/09/25 Roll No:10

Program/Experiment NO: 4
Program/Experiment Name: Illustrate with a suitable example the use of
Toast to display a message in an Android application.

Description: This program demonstrates how to use Toast in an Android


application to display a short pop-up message to the user. Toast provides
simple feedback about an operation in a small popup.

XML Code:

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

<LinearLayout xmlns:android="[Link]

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:gravity="center"

android:padding="16dp">

<Button

android:id="@+id/btnShowToast"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Show Toast" />

</LinearLayout>

PMC 301 Mobile Application Development Laboratory Section:


A
Date: 01/09/25 Roll No:10

XML Layout

JAVA Code:

package [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];
PMC 301 Mobile Application Development Laboratory Section:
A
Date: 01/09/25 Roll No:10

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

Button btnShowToast = findViewById([Link]);

[Link](new [Link]() {

@Override

public void onClick(View v) {

[Link]([Link], "Hello! This is a Toast message.",


Toast.LENGTH_SHORT).show();

});

Output:

PMC 301 Mobile Application Development Laboratory Section:


A
Date: 01/09/25 Roll No:10

PMC 301 Mobile Application Development Laboratory Section:


A
Date: 01/09/25 Roll No:10

PMC 301 Mobile Application Development Laboratory Section:


A

You might also like