I am making an application and it has an Alert Dialog in it.
Now i am checking some data I got from AlertDialog editTexts in dialog Positive button OnClick method but
This is the trick (override onClickListener inside onShowListener):
final AlertDialog d = new AlertDialog.Builder(context)
.setView(v)
.setTitle(R.string.my_title)
.setPositiveButton(android.R.string.ok,
new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface d, int which) {
//Do nothing here. We override the onclick
}
})
.setNegativeButton(android.R.string.cancel, null)
.create();
d.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button b = d.getButton(AlertDialog.BUTTON_POSITIVE);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// TODO Do something
//Dismiss once everything is OK.
d.dismiss();
}
});
}
});