AlertDialog alertDialog = new AlertDialog.Builder(
AlertDialogActivity.this).create (); // Setting Dialog Title alertDialog.setTitle("Alert Dialog"); // Setting Dialog Message alertDialog.setMessage("Welcome to AndroidHive.info"); // Setting Icon to Dialog alertDialog.setIcon(R.drawable.tick); // Setting OK Button alertDialog.setButton("OK", new DialogInterface.OnClickListener( ) { public void onClick(DialogInterface dialog, int which) { // Write your code here to execute after dialog closed Toast.makeText(getApplicationContext(), "You cli cked on OK", Toast.LENGTH_SHORT).show(); } }); // Showing Alert Message alertDialog.show(); Android alert dialog with two button AlertDialog.Builder alertDialog = new AlertDialog.Builder(AlertDialogActivity.th is); // Setting Dialog Title alertDialog.setTitle("Confirm Delete..."); // Setting Dialog Message alertDialog.setMessage("Are you sure you want delete this?"); // Setting Icon to Dialog alertDialog.setIcon(R.drawable.delete); // Setting Positive "Yes" Button alertDialog.setPositiveButton("YES", new DialogInterface.OnClick Listener() { public void onClick(DialogInterface dialog,int which) { // Write your code here to invoke YES event Toast.makeText(getApplicationContext(), "You clicked on YES", Toast.LENGTH_SHORT).show(); } }); // Setting Negative "NO" Button alertDialog.setNegativeButton("NO", new DialogInterface.OnClickL istener() { public void onClick(DialogInterface dialog, h) { // Write your code here to invoke NO event
int whic
Toast.makeText(getApplicationContext(), "You clicked on
NO", Toast.LENGTH_SHORT).show(); dialog.cancel(); } }); // Showing Alert Message alertDialog.show(); Android alert dialog with three button AlertDialog.Builder alertDialog = new AlertDialog.Builder(AlertDialogActivity.th is); // Setting Dialog Title alertDialog.setTitle("Save File..."); // Setting Dialog Message alertDialog.setMessage("Do you want to save this file?"); // Setting Icon to Dialog alertDialog.setIcon(R.drawable.save); // Setting Positive "Yes" Button alertDialog.setPositiveButton("YES", new DialogI nterface.OnClickListener() { public void onClick(DialogInterface dial og, int which) { // User pressed YES button. Write Logic Here Toast.makeText(getApplicationContext(), "You clicked on YES", Toast.LENGTH_SHORT).show(); } }); // Setting Negative "NO" Button alertDialog.setNegativeButton("NO", new DialogIn terface.OnClickListener() { public void onClick(DialogInterface dial og, int which) { // User pressed No button. Write Logic H ere Toast.makeText(getApplicationContext(), "You clicked on NO", Toast.LENGTH_SHORT).show(); } }); // Setting Netural "Cancel" Button alertDialog.setNeutralButton("Cancel", new Dialo gInterface.OnClickListener() { public void onClick(DialogInterface dial og, int which) { // User pressed Cancel button. Write Log ic Here Toast.makeText(getApplicationContext(), "You clicked on Cancel",