Monday, December 2, 2013

How to Show Alert Dialog in Android (with Pictures)

In Android, you can add alerts to your application to get the users focus on something, like an update. The AlertDialog class is used to display an alert. Here's how to implement the functionality into your app.
STEPS



1
IMPORT THE ALERTDIALOG CLASS TO YOUR ANDROID APPLICATION.
import android.app.AlertDialog;



2
SET UP THE ALERTDIALOG CLASS TO THE BODY OF YOUR APPLICATION LIKE THIS. Set some properties for the AlertDialog object.
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Reset...");
alertDialog.setMessage("Are you sure?");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// here you can add functions
alertDialog.setIcon(R.drawable.icon);
alertDialog.show();


3
SAVE YOUR APPLICATION AND RUN. You will get the image as below.
VIDEO

No comments:

Post a Comment