Skip to content

Instantly share code, notes, and snippets.

@rezaiyan
Created October 28, 2017 08:21
Show Gist options
  • Save rezaiyan/88a0fce6c4c270c57b347ff2a38407d6 to your computer and use it in GitHub Desktop.
Save rezaiyan/88a0fce6c4c270c57b347ff2a38407d6 to your computer and use it in GitHub Desktop.
This is AlertDialogBuilder with abstaction that can decrease boilerplate
public abstract class AlertBuilder {
public abstract void ok();
public AlertDialog.Builder create(Context context, String message) {
final AlertDialog.Builder builder;
builder = new AlertDialog.Builder(context);
builder.setMessage(message)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
AlertBuilder.this.ok();
}
})
.setNegativeButton(android.R.string.no, null);
return builder;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment