AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setMessage("Are you sure you want to delete this item?") .setCancelable(false) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show();
AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setMessage("Are you sure you want to exit?") .setCancelable(false) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // Do nothing } }) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { finish(); } }); AlertDialog alert = builder.create(); alert.show();Package library: android.app