It is useful to display confirmation dialogs in your app to prevent accidental presses.
There is an inbuilt feature to do that, and its called the AlertDialog Builder.
This may look a bit messy, but its all chained together. You can split it up into separate calls if you want to make it look a bit neater.
01.
AlertDialog.Builder ad =
new
AlertDialog.Builder(activity);
02.
ad.setIcon(android.R.drawable.ic_dialog_alert) .setTitle(
"Quit game?"
)
03.
.setMessage(
"Are you sure you want to leave this game?"
)
04.
.setNegativeButton(android.R.string.cancel,
new
DialogInterface.OnClickListener() {
05.
@Override
06.
public
void
onClick(DialogInterface dialog,
int
which) {
07.
// User said no, resume game?
08.
}
09.
})
10.
.setPositiveButton(android.R.string.ok,
new
DialogInterface.OnClickListener() {
11.
@Override
12.
public
void
onClick(DialogInterface dialog,
int
which) {
13.
// Stop the activity
14.
}
15.
});
16.
17.
ad.show();