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