Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Last active December 10, 2019 17:18
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 magdamiu/920d90db6d12a33abbb0e824db587754 to your computer and use it in GitHub Desktop.
Save magdamiu/920d90db6d12a33abbb0e824db587754 to your computer and use it in GitHub Desktop.
Create and show an AlertDialog with buttons
// setup the alert builder
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.notice));
builder.setMessage(getString(R.string.alert_title));
// add the buttons
builder.setPositiveButton(getString(R.string.launch_app), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(AlertsActivity.this, getString(R.string.launch_app) + " " + getString(R.string.click), Toast.LENGTH_SHORT).show();
}
});
builder.setNeutralButton(getString(R.string.reminde_me), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(AlertsActivity.this, getString(R.string.reminde_me) + " " + getString(R.string.click), Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(AlertsActivity.this, getString(R.string.cancel) + " " + getString(R.string.click), Toast.LENGTH_SHORT).show();
}
});
// create and show the alert dialog
AlertDialog dialog = builder.create();
dialog.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment