title: AlertDialog: Can't keep dialog when the condition fails
body: <p>I have an AlertDialog with a view as shown below.</p>
  
  <pre><code>userEmail = new EditText(mActivity);
  userEmail.setSingleLine(true);
  
  userEmail.setHint("Email address");
  userEmail.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
  userEmail.addTextChangedListener(this);
  
  AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
  builder.setTitle(getResources().getString(R.string.text_dialog_email));
  builder.setView(userEmail);
  </code></pre>
  
  <p>I have added a POSITIVE button to it with an event listener.</p>
  
  <pre><code>builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            if(userEmail.getText().toString().trim().length() &lt;= 0) {
                  userEmail.setError("Email address can't be empty");
            } else {
                    //some logic
  
                   InputMethodManager imm = (InputMethodManager) mActivity.getSystemService(Activity.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(userEmail.getWindowToken(), 0);
  
                   dialog.dismiss(); 
             }
  
  } });
  
  builder.create();
  builder.show();
  </code></pre>
  
  <p>There is an email validation when user hits ok button. I was expecting the dialog to stay if the Edittext is empty. However, in real, dialog disappears even if the EditText is empty.</p>
  
  <p>Is there anything I am lacking?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The whole code is inside a method, openEmailDialog(). It is invoked on a buttonclick.</p>
  
  <pre><code>@Override
  public void onClick(View view) {
     openEmailDialog();
  }
  </code></pre>