Android AlertDialog, Yes No Cancel and Item List

android-alertdialog-yes-no-cancelAndroid AlertDialog, Yes No Cancel and Item List

Source code AlertDialog Yes, No, Cancel :

//import android.app.AlertDialog;
new AlertDialog.Builder(this)
    .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 with delete
        }
     })
    .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();

Source code AlertDialog Item List :

//import android.app.AlertDialog;
final CharSequence[] dialogitem = {"Add", "Edit", "Delete"};
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Action ?");
builder.setItems(dialogitem, new DialogInterface.OnClickListener() {
	public void onClick(DialogInterface dialog, int item) {
		switch(item){
		case 0 :
			// action add

			break;
		case 1 :
			// action edit

			break;
		case 2 :
			// action del

			break;
		}
	}
});
builder.create().show();

Result :

android-alertdialog-yes-no-cancel

Download Source Code

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>