Is there a way to override the behavior of alert dialog box on clicking of neutral button or negative button to not auto dismiss .
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(false);
builder.setTitle("Title");
builder.setPositiveButton("Done", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do something and close dialog
}
});
builder.setNeutralButton("Clear All", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do something but not close dialog
}
});
builder.setMultiChoiceItems(items, checkedItems, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int which, boolean isChecked) {
if(isChecked){
// do something
} else {
// do something else
}
}
});
final AlertDialog dialog = builder.create();
dialog.show();
The expected behavior of negative button here is : on clicking of "Clear All" it should just clear the selection that's all and not automatically close the dialog.? But Android alertDialog automatically closes the dialog, on click of NegativeButton or NeutralButton. Any way to override this behavior