Created
April 14, 2024 10:27
-
-
Save VahidHoseini-ir/23e95dc520ad778370983019c354d0b2 to your computer and use it in GitHub Desktop.
code to show alert dialog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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