title: AlertDialog Custom layout views not accessible android
body: <p>I have a method responsible for showing <code>AlertDialog</code> and it has a custom layout which includes a <code>EditText</code>, and OnPositive button click I am trying to get the value of edit text but the <code>EditText.getText()</code> always return empty.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>private void showForgetPassDialog() {
  
          final View view = getLayoutInflater().inflate(R.layout.alert_dialog_forgot_pass, null);
  
          AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
          builder.setCancelable(false);
          builder.setTitle(getString(R.string.forgot_password));
          builder.setMessage(getString(R.string.reset_pass));
          final EditText emailTxt  = (EditText) view.findViewById(R.id.email_field);
          emailReset = emailTxt.getText().toString();
          String positiveText = getString(R.string.submit);
          builder.setPositiveButton(positiveText,
                  new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                          Toast.makeText(LoginActivity.this, "test :"+emailReset, Toast.LENGTH_SHORT).show();
                          if(!emailReset.equals("") &amp;&amp; isValidEmail(emailReset)){
                              resetPassword(emailReset);
                          }else{
                              emailTxt.setError(getString(R.string.error_email));
                          }
  
                      }
                  });
  
          String negativeText = getString(R.string.cancel);
          builder.setNegativeButton(negativeText,
                  new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                          dialog.dismiss();
                      }
                  });
  
          final AlertDialog dialog = builder.create();
          dialog.setOnShowListener(new DialogInterface.OnShowListener() {
              @Override
              public void onShow(DialogInterface dialogInterface) {
                  dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(ContextCompat.getColor(LoginActivity.this,R.color.colorAccentDark));
                  dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(LoginActivity.this,R.color.PrimaryBlue));
  
              }
          });
          dialog.setView(view);
          // display dialog
          dialog.show();
      }
  </code></pre>
  
  <blockquote>
    <p>XML:</p>
  </blockquote>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_marginLeft="10dp"
      android:layout_marginStart="10dp"
      android:layout_marginRight="10dp"
      android:layout_marginEnd="10dp"
      &gt;
      &lt;EditText
          android:textCursorDrawable="@null"
          android:id="@+id/email_field"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerInParent="true"
          android:ellipsize="start"
          android:gravity="center_horizontal"
          android:hint="@string/email_label"
          android:inputType="textEmailAddress"
          android:textColor="#484848" /&gt;
  
      &lt;View
          android:id="@+id/login_bar"
          android:layout_width="match_parent"
          android:layout_height="1dp"
          android:layout_below="@+id/email_field"
          android:background="#e1e1e1" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>