Skip to content

Instantly share code, notes, and snippets.

@georgismitev
Created January 17, 2015 11:45
Show Gist options
  • Save georgismitev/2db86d30488e9a248ff5 to your computer and use it in GitHub Desktop.
Save georgismitev/2db86d30488e9a248ff5 to your computer and use it in GitHub Desktop.
android show an alert dialog
addHomeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
// set title
alertDialogBuilder.setTitle("Your Title");
// set dialog message
alertDialogBuilder
.setMessage("Click yes to exit!")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
MainActivity.this.finish();
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment