Skip to content

Instantly share code, notes, and snippets.

@girish3
Last active November 11, 2018 05:07
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 girish3/4709a2097c6128ce1a8ca3740c5878d6 to your computer and use it in GitHub Desktop.
Save girish3/4709a2097c6128ce1a8ca3740c5878d6 to your computer and use it in GitHub Desktop.
[Alert Dialog] Alert dialog is created using a builder pattern #android_snippet #android
// this is a context
AlertDialog.Builder builder = new AlertDialog.Builder(this);
// Check other builder methods like setCancelable, setIcon..
builder.setTitle("Set Title");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// do something
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// do something
}
});
AlertDialog dialog = builder.create();
dialog.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment