Skip to content

Instantly share code, notes, and snippets.

@VahidHoseini-ir
Created April 14, 2024 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VahidHoseini-ir/23e95dc520ad778370983019c354d0b2 to your computer and use it in GitHub Desktop.
Save VahidHoseini-ir/23e95dc520ad778370983019c354d0b2 to your computer and use it in GitHub Desktop.
code to show alert dialog
private void showAlertDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.outline_error_24);
builder.setTitle("Alert Dialog");
builder.setMessage("This is an alert dialog.");
builder.setPositiveButton("OK", (dialog, which) -> dialog.dismiss());
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getBaseContext(), "Show Alert Dialog Canceled", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment