0% found this document useful (0 votes)
12 views2 pages

Displaying Alert Messages in Android

This document provides a code sample to display an alert message in an Android application. The code creates an AlertDialog with positive and negative buttons and a title and message. It defines an OnClickListener for the buttons that contains a switch statement to perform different actions depending on which button is clicked. The AlertDialog is then built and shown to display the message and buttons in response to an event, such as a button click.

Uploaded by

Ajaypal Yadav
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)
12 views2 pages

Displaying Alert Messages in Android

This document provides a code sample to display an alert message in an Android application. The code creates an AlertDialog with positive and negative buttons and a title and message. It defines an OnClickListener for the buttons that contains a switch statement to perform different actions depending on which button is clicked. The AlertDialog is then built and shown to display the message and buttons in response to an event, such as a button click.

Uploaded by

Ajaypal Yadav
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

Display Alert message in Android

How to display Alert message in Android Application?


Here is a sample code of an application that explains how you can display a simple Alert
message in your Android application. The below code can be put on a button click event or
wherever you would like it to popup.

[Link] dialogClickListener
= [Link]() { /*DialogInterface called while setting
the AlertDialog Buttons */
public void onClick(DialogInterface dialog, int which) {
//Here you can perform functions of Alert Dialog Buttons as shown
switch (which){
case DialogInterface.BUTTON_POSITIVE:
//Yes button clicked
break;
case DialogInterface.BUTTON_NEGATIVE:
//No button clicked

break;
}
}
};
[Link] builder = new [Link](this);
[Link]("Alert Dialog");// Set the Title of Alert Dialog
[Link]("Are you sure?")
.setPositiveButton("Yes",dialogClickListener)
.setNegativeButton("No", dialogClickListener).show();/* Setting the Alert
message with buttons Yes and No */

//You can also set the icon of Alert Dialog using this code
[Link]([Link]);

You might also like