title: Android: How do I retrieve Edittext.getText() in custom AlertDialog?
body: <p>The topic explains what i'm after... I can't retrieve the EditText from my custom view in android. All I get is a Nullpointer Exception. :/
  I've marked where the problems are in the code with comments.
  The ID:s are correct and my XML layout is a simple RelativeLayout containing two EditText attributes.
  Obviously I'm missing something trivial here, but I've now stared at the code for almost 2 hours without solving this, so I thought I'll give SO a try instead.</p>
  
  <pre><code>protected void showLoginDialog() {
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      // Get the layout inflater
      LayoutInflater inflater = this.getLayoutInflater();
  
      // Inflate and set the layout for the dialog
      // Pass null as the parent view because its going in the dialog layout
      builder.setView(inflater.inflate(R.layout.activity_login, null))
      // Add action buttons
      .setPositiveButton(R.string.login, new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int id) {
  
              /* ERROR HERE! */
              EditText uName, passWord;
              uName = (EditText) findViewById(R.id.login_username);
              passWord = (EditText) findViewById(R.id.login_password);
  
              Log.i(TAG, uName.getText().toString() + " " + passWord.getText().toString());
              /* STOP */
  
              if(the_view.getSocketTask().isConnected) {
                  the_view.getSocketTask().send_command("LOGIN ");
              } else {
                  showToast("Not connected!");
              }
          }
      })
      .setNegativeButton(R.string.cancel,  new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int id) {
              dialog.dismiss();
          }
      });      
      builder.create().show();
  }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>After suggestions the following code is a working one! Thanks again!</p>
  
  <pre><code>protected void showLoginDialog() {
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      // Get the layout inflater
      LayoutInflater inflater = this.getLayoutInflater();
  
  
  
      // Inflate and set the layout for the dialog
      // Pass null as the parent view because its going in the dialog layout
      builder.setView(inflater.inflate(R.layout.activity_login, null))
      // Add action buttons
      .setPositiveButton(R.string.login, new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int id) {
              Dialog f = (Dialog) dialog;
              /* ERROR HERE! */
              EditText uName, passWord;
              uName = (EditText) f.findViewById(R.id.login_username);
              passWord = (EditText) f.findViewById(R.id.login_password);
  
              Log.i(TAG, uName.getText().toString() + " " + passWord.getText().toString());
              /* STOP */
  
              if(the_view.getSocketTask().isConnected) {
                  the_view.getSocketTask().send_command("LOGIN ");
              } else {
                  showToast("Not connected!");
              }
          }
      })
      .setNegativeButton(R.string.cancel,  new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int id) {
              dialog.dismiss();
          }
      });      
      builder.create().show();
  }
  </code></pre>
  
  <p>Thanks in advance! 
  Alex</p>