Android Alert Dialog Example sample Tutorial

By | September 12, 2015

Alert dialog is used in android whenever we need to notify user about certain events in our android application. Such events include exiting of app,deleting some entry, network usage etc.

android alert dialog example code
We will see a simple code snippet showing the implementation of alert dialog in android as below:

new AlertDialog.Builder(context)
    .setTitle("Delete entry")
    .setMessage("Are you sure you want to delete this entry?")
    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // continue  deletion
        }
     })
    .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // do nothing
        }
     })
    .setIcon(android.R.drawable.ic_dialog_alert)
     .show();

3,225 total views, 1 views today

(Visited 716 times, 1 visits today)