title: ViewStub reinflates last view inflated on first pass of onCreate
body: <p>I have a bug with my activity.</p>
  
  <p>I have three view stubs in my linear layout like so - </p>
  
  <pre><code>&lt;ViewStub 
   android:id="@+id/index_1"
   android:layout="@layout/index_edittext" 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content" /&gt;
  &lt;ViewStub 
   android:id="@+id/index_2"
   android:layout="@layout/index_edittext" 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content" /&gt;
  &lt;ViewStub 
   android:id="@+id/index_3"
   android:layout="@layout/index_edittext" 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content" /&gt;
  </code></pre>
  
  <p>my onCreate conditionally checks what to inflate:  </p>
  
  <pre><code>for (int i = 0; i &lt; 3; i++) {
      int id = convertIndexToId(i); //will turn i into R.id.index_1
      ViewStub stub = findViewById(id);
      if (bShouldBeSpinner) {
          stub.setLayoutResource(R.layout.index_spinner);
          View root = stub.inflate();
          Spinner spin = (Spinner)root.findViewById(R.id.my_spinner);
          spinner.setAdapter(adapter);
          spinner.setSelection(0);
      }
      else {
          stub.setLayoutResource(R.layout.index_edittext);
          View root = stub.inflate();
          EditText et = (EditText)root.findViewById(R.id.my_edittext);
          //et.phoneHome(); just kidding
          et.setText(String.valueOf(System.currentTimeMillis()));
      }
  }
  </code></pre>
  
  <p>I force bShouldBeSpinner to false. The output of the edittext's is as follows:<br>
  1300373517172<br>
  1300373517192<br>
  1300373517221 </p>
  
  <p>However, when I rotate the screen and onCreate is called a second time the output is this:<br>
  1300373517221<br>
  1300373517221<br>
  1300373517221</p>
  
  <p>Initially that made me think you should only inflate the view once, and the heirarchy is kept inbetween onCreate's... however when i only run it the first time the second time no views are shown for the stubs.</p>
  
  <pre><code>&lt;LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"&gt;
      &lt;Spinner style="@style/SearchInput" android:id="@+id/my_spinner" /&gt;
  &lt;/LinearLayout&gt;
  
  &lt;LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"&gt;
      &lt;EditText style="@style/SearchInput" android:id="@+id/my_edittext" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I feel the documentation is assuming something that I did not notice or am missing. Does anyone see what I am doing wrong?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I added to the view stubs android:inflatedId="index_1_root"... etc</p>
  
  <p>it is the strangest thing, when I add these lines after the for loop:</p>
  
  <pre><code>EditText v = indexRoot1.findViewById(R.id.index_edit_text);
  Log.d(TAG, "EditTExt: " + v);
  
  EditText v2 = indexRoot2.findViewById(R.id.index_edit_text);
  Log.d(TAG, "EditTExt: " + v2);
  </code></pre>
  
  <p>the output says (I believe) they are references to different EditTexts. </p>
  
  <blockquote>
    <p>EditTExt: android.widget.EditText@47210fe8<br>
    EditTExt: android.widget.EditText@47212ba8  </p>
  </blockquote>
  
  <p>So they are getting inflated again, but the text is set to what the last edittext was set to on the first pass.</p>