Created
January 17, 2015 11:45
-
-
Save georgismitev/2db86d30488e9a248ff5 to your computer and use it in GitHub Desktop.
android show an alert dialog
This file contains hidden or 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
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