My simple code here shows a Dialog in Android. I want to not hide the dialog when the user clicks outside the dialog or the dialog loses focus. How can I do it?
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
Toast.makeText(getApplicationContext(), "yes", Toast.LENGTH_LONG).show();
break;
case DialogInterface.BUTTON_NEGATIVE:
Toast.makeText(getApplicationContext(), "no", Toast.LENGTH_LONG).show();
break;
}
}
};
And the button code is:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure?")
.setPositiveButton("Yes", dialogClickListener)
.setNegativeButton("No", dialogClickListener).show();
Thanks.
use this for hiding if clicked outside
dialog.setCanceledOnTouchOutside(true);or use this for NOT hiding if clicked out side
dialog.setCanceledOnTouchOutside(false);