title: How do I get edittext value from a custom AlertDialog where retrieval of values is not in the onClick?
body: <p>What I am trying to do is to create a custom dialog that overrides an AlertDialog.
  What it is supposed to do is get some text (at least 2 strings) and then for each of those strings it is supposed to be able to get more information, but I want to do this in custom dialogs.
  So what is supposed to happen is a user can enter 2 people in an activity screen, and then for the first person, you get a custom dialog and that person can enter three words, and then it jumps to the next custom dialog (exact same layout I am inflating) and the second person can enter some words.</p>
  
  <p>This is my xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/LinLay_Enter_Words"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent" &gt;
  &lt;TextView
      android:id="@+id/TextView_AddPlayerWord_Instruction"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textSize="@dimen/help_text_size"
      android:textStyle="bold"&gt;&lt;/TextView&gt;  
  &lt;EditText
      android:id="@+id/EditText_Word1"
      android:layout_height="wrap_content"
      android:maxLength="20"
      android:layout_width="match_parent"
      android:maxLines="1"&gt;&lt;/EditText&gt;
  &lt;EditText
      android:id="@+id/EditText_Word2"
      android:layout_height="wrap_content"
      android:layout_width="match_parent"
      android:maxLines="1"&gt;&lt;/EditText&gt;
  &lt;EditText
      android:id="@+id/EditText_Word3"
      android:layout_height="wrap_content"
      android:layout_width="match_parent"
      android:maxLines="1"&gt;&lt;/EditText&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>And this is part of the code:</p>
  
  <pre><code>protected Dialog onCreateDialog(int id) {
      switch (id) {
      case  NOUN_INPUT_DIALOG_ID:
          Dialog returnedDialog = initWordDialog();
          return(returnedDialog);
      }
      return null; 
  }
  </code></pre>
  
  <p>It calls initWordDialog():</p>
  
  <pre><code>private Dialog initWordDialog() {
      LayoutInflater inflater = LayoutInflater.from(this); //(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      final View dialogLayout = inflater.inflate(R.layout.word_entry_dialog, null);
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
  
      ...
      TextView v1 = (TextView) dialogLayout.findViewById(R.id.TextView_AddPlayerWord_Instruction);
      ...
  v1.setText("SomeText");
  
      builder.setView(dialogLayout);
      builder.setTitle(R.string.enter_word_title);
      builder.setPositiveButton("Next", onNextSubmit);
      AlertDialog wordBuilderDialog = builder.create();
      return wordBuilderDialog;
  }
  </code></pre>
  
  <p>I think what I am trying to find has been discussed to some degree here:
  <a href="https://stackoverflow.com/questions/8398375/value-of-edittext-in-custom-dialog">Value of EditText in Custom Dialog</a>
  <a href="https://stackoverflow.com/questions/6626006/android-custom-dialog-cant-get-text-from-edittext">Android - Custom Dialog - Can&#39;t get text from EditText</a>
  <a href="https://stackoverflow.com/questions/3426917/how-to-add-two-edit-text-fields-in-an-alert-dialog">How to add two edit text fields in an alert dialog</a>
  The problem, I believe, lies here, where all of the examples everyone has their onClick in the same function as their onCreate. My stuff was a bit more complicated and I wanted to separate out the functions; however, as a result, I am now unable to access any of the EditText variables.</p>
  
  <p>Here is my onClick implementation:</p>
  
  <pre><code>private DialogInterface.OnClickListener onNextSubmit = new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {
          if (setPlayerWords()) {
          ...
      }
  };
  </code></pre>
  
  <p>The part that matters is I don't even get to the part where I'm accessing the edittexts until setPlayerWords is called, and this is where it is failing:</p>
  
  <pre><code>public boolean setPlayerWords() {
      PMGamePlay pmObj = (PMGamePlay) getApplicationContext();
      String[] playerWords = new String[pmObj.numberOfWordsPlayersGetToInput()];
  
      //LayoutInflater inflater = LayoutInflater.from(this);
      //View dialogLayout2 = inflater.inflate(R.layout.word_entry_dialog, null);
      //setContentView(R.layout.word_entry_dialog);
      final LinearLayout myLayout = (LinearLayout) findViewById(R.id.LinLay_Enter_Words);
      final EditText w0 = (EditText) myLayout.findViewById(R.id.EditText_Word1);
      final EditText w1 = (EditText) myLayout.findViewById(R.id.EditText_Word2);
      final EditText w2 = (EditText) myLayout.findViewById(R.id.EditText_Word3);
      String test = w0.getText().toString();
  
      playerWords[0] = w0.getText().toString();
      playerWords[1] = w1.getText().toString();
      playerWords[2] = w2.getText().toString();
  
      ...
      return true;
  }
  </code></pre>
  
  <p>I initially tried re-inflating, but that seemed to reset and while the edittexts would not be null, they were reset to have "" in their values.
  Then I tried to setContentView on my xml file, but that still gave me a null value.
  Now, I just try and simply access the linearlayout, and that also returns a null value.  If I just try to access the edittexts by their id directly without first going through its parent linearlayout, it also returns a null value.  </p>
  
  <p>At this point, I'm not sure what to do other than to cram everything that I have in these separate functions into the same single onclick, but I really don't want to do that.  Is there nothing else I can do to access these edittexts?</p>
  
  <p>Any help would be greatly appreciated!</p>