final AlertDialog alertDialog = new AlertDialog.Builder(this) .setMessage("Are you sure you want to delete this item?") .setPositiveButton("Delete", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { // delete the item } }) .setNegativeButton("Cancel", null) .create(); alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogInterface) { Toast.makeText(MainActivity.this, "Action canceled", Toast.LENGTH_SHORT).show(); } }); alertDialog.show();In this example, we create an AlertDialog with a positive button labeled "Delete" and a negative button labeled "Cancel". We also set the onCancelListener to show a short toast message indicating that the action was canceled. Finally, we show the alert dialog to the user. The package library for this class is "android.app".