In my application I am showing a custom AlertDialog for the user to enter the a string. When the user presses the positive button, there should be an AsyncTask in order to check the string provided by the user. If the check is successful I want to dismiss() the AlerDialog, on the other hand, if the check fails I want the AlerDialog to stay visible for the user to make the necessary corrections.
The problem is that I have no idea how to avoid the AlerDialog to dismiss after click of any of the buttons (I have checked with all of them).
None of the answers I have found here like this question seem to work.
Here is my piece of code
LayoutInflater inflater = getActivity().getLayoutInflater();
View dialogView = inflater.inflate(R.layout.generic_textinput_dialog, null);
final EditText editText = (EditText) dialogView.findViewById(R.id.generic_dialog_text_editText);
editText.setHint("Username");
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
dialogBuilder.setMessage("Share xxx");
dialogBuilder.setPositiveButton("Share", new DialogInterface.OnClickListener() {
    @Override
    public void onClick (DialogInterface dialog, int which) {
        String sharingUser = editText.getText().toString();
        if (!TextUtils.isEmpty(sharingUser)) {
            doSomething();
        }
        actionMode.finish();
    }
});
dialogBuilder.setNegativeButton("Cancel", null);
dialogBuilder.setView(dialogView);
dialogBuilder.show();
Any idea how to solve this issue?
NOTES
- Obviously, I am not making use of dialog.dismiss()anywhere an even though the Dialog is dismissed after clicking any of the buttons.
- I am using API v23.1.1.
 
     
    