Last active
December 10, 2019 17:18
-
-
Save magdamiu/920d90db6d12a33abbb0e824db587754 to your computer and use it in GitHub Desktop.
Create and show an AlertDialog with buttons
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
// 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