In my application I have a point where I need to save a customer.
I do some checks to verify if every field has a value and then i need to prompt a dialog if someone is blank, send back a boolean value and, based on its value save or not the customer.
Here is my code:
private boolean canBeSaved(ArrayList<View> viewList) {
if (!viewList.isEmpty()) {
showErrorDialog();
for (View v : viewList) {
((EditText) v).setError("errorMsg");
v.requestFocus();
}
return false;
} else {
return true;
}
}
private void showErrorDialog() {
QustomDialogBuilder saveDialog = new QustomDialogBuilder(this);
saveDialog.setTitle("ATTENZIONE!");
saveDialog.setMessage(Constants.CANT_SAVE);
saveDialog.setNeutralButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
saveDialog.show();
}
but after executing showErrorDialog();
I cannot wait onClick
event to resume the flow.
The flow I got at the moment is: showErrorDialog() -> dialog.show() -> rest of canBeSaved(..)
The flow I want is: showErrorDialog() -> dialog.show() -> wait onClickEvent -> rest of canBeSaved(..)
Is this possible or I'm asking the moon? I'm doing everything wrong?