title: Adding multiple child views to parent view
body: <p>I have a <code>LinearLayout</code> view element inside a <code>ScrollView</code> (<strong>main.xml</strong>):</p>
  
  <pre><code>&lt;ScrollView ...&gt;
  
     &lt;LinearLayout
         android:id="@+id/root"
         android:orientation="vertical"
      &gt;
            &lt;TextView .../&gt;
            &lt;EditText .../&gt;
            ...
      &lt;/LinearLayout&gt;
  
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>As you see above, there are also some other elements inside the <em>root</em> <code>LinearLayout</code> .</p>
  
  <p>Now, I would like to programmatically(dynamically) add more views to the <code>LinearLayout</code> (id="root"). </p>
  
  <p><strong>I tried the following way to add more child views</strong> to this <em>root</em>:</p>
  
  <p><strong>Firstly,</strong> I created my child view which is in a separate layout file:</p>
  
  <p><strong>child.xml</strong></p>
  
  <pre><code>&lt;LinearLayout
      android:id="@+id/child"
  &gt;
       &lt;TextView id="mytxt"... /&gt;
       &lt;ListView id="mylist".../&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>Secondly,</strong> I inflate &amp; get two instances of above child view, initialize elements inside:</p>
  
  <pre><code>/***inflate 1st child, initialize its elements***/
  LinearLayout child_1 = (LinearLayout) inflater.inflate(R.layout.child, null);
  TextView txt1 = (TextView)child_1.findViewById(R.id.mytxt);
  txt1.setText("CAR");
  ListView list1 = (ListView)child_1.findViewById(R.id.mylist);
  // Code to initialize 'list1' (I did not paste code here)
  
  
  /*** inflate 2nd child, initialize its elements ****/
  LinearLayout child_2 = (LinearLayout) inflater.inflate(R.layout.child, null);
  TextView txt2 = (TextView)child_2.findViewById(R.id.mytxt);
  txt2.setText("PLANE");
  ListView list2 = (ListView)child_2.findViewById(R.id.mylist);
  // Code to initialize 'list2' (I did not paste code here)
  </code></pre>
  
  <p><strong>Finally</strong>, I add them to <em>root</em> <code>LinearLayout</code>: </p>
  
  <pre><code>//get root
  View contentView = inflater.inflate(R.layout.main, null);
  LinearLayout root = (LinearLayout) contentView.findViewById(R.id.root);
  
  //add child views
  root.add(child_1);
  root.add(child_2);
  </code></pre>
  
  <p>When I run my app on device, I can only see <code>child_2</code> layout without seeing <code>child_1</code> under 'root', why??</p>