title: Dynamically include another layout in Fragment Activity
body: <p>This is my Home.xml layout file</p>
  
  <pre><code>  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/rellay"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" 
      android:background="@drawable/placesgradient"&gt;
  
      &lt;Button
          android:id="@+id/btn2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:text="click" 
          /&gt;
  
      **&lt;I want to include another layout here on a click of a button dynamically on click of a button &gt;**
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="20dp"
         android:layout_below="@id/btn2"
          android:text="hello this is text..see above" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>This is my Home.java file</p>
  
  <pre><code>public class Home extends Fragment implements OnClickListener {
      Button b1;
      RelativeLayout r1;
      View rootView;
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
  
          rootView = inflater.inflate(R.layout.home, container, false);
          b1 = (Button) rootView.findViewById(R.id.btn2);
          b1.setOnClickListener(this);
  
          return rootView;
      }
  
      @Override
      public void onClick(View arg0) {
          ViewGroup con = null;
          r1 = (RelativeLayout) rootView.findViewById(R.id.rellay);
          LayoutInflater layoutInflater = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
          r1.addView(layoutInflater.inflate(R.layout.test1, con , false));
  
      }
  }
  </code></pre>
  
  <p>When I click on the button it places the test1.xml layout file at the top of the home.xml layout.  I need it to be between the button and the text.  I checked this code on stack before but it doesn't seem to work with the FragmentActivity. Here 1 indicates the index or the second child in this case.</p>
  
  <pre><code>rl.addView(1, layoutInflater.inflate(R.layout.content_layout, this, false) );
  </code></pre>
  
  <p>How can I achieve it?  Help!!</p>