Is there some way to do validation upon clicking ok. Im not dismissing it but it closes when I click Ok. I have written a custom AlertDialog that uses some edit texts. Probl
if you write nothing inside onClick method definately it will dismiss whether you want or not, then why you asking this question as you have not write anything inside that method. as It is alertdialog it will get closed and if you dont want it close then use setNeutralButton instead of setPositiveButton. It wont close if you use neutral button
You can do this by overriding the onClickListener. The trick is to get the button after create and showing the dialog.
// Create you dialog here and show it
...
dialog.show();
Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
positiveButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View onClick) {
// Valid checking
...
if (valid) {
dialog.dismiss();
} else {
// Not valid
}
}
});