Trying to debug a bit of code. I have a AlertDialog with a positive and negative listener set. On an Android 2.3.3 device everything works as expected. A user has to choose between two options in order to continue. However, on my 4.1.1 device a user can click anywhere on the screen to dismiss the dialog. Not sure what is getting called that is dismissing the dialog box. I’ve looked at Android AlertDialog and AlertDialog.Builder but I can’t find any helpful information. Any help on why this is occurring would be appreciated. The code for the dialog is below
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getString(R.string.titleString));
builder.setPositiveButton(this.getResources().getString(R.string.option1),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Things Happen Here
dialog.cancel();
}
});
builder.setNegativeButton(this.getResources().getString(R.string.option2),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Things Happen Here
dialog.cancel();
}
});
AlertDialog demoAlert = builder.create();
demoAlert.show();
Try setting
cancelableto false: