title: Create views programmatically using XML on Android
body: <p>I want to create a UI layout in XML and have it inserted as a child into an existing view (It will be inserted multiple times). </p>
  
  <p>For example, here is what the XML file will contain:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;RelativeLayout
      android:id="@+id/relativeLayout1" &gt;
      &lt;Button android:id="@+id/myButton"
          android:text="@string/mystring" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Now I get the parent <code>LinearLayout</code> and now want to add that XML file as a child view, e.g:</p>
  
  <pre class="lang-java prettyprint-override"><code>LinearLayout linear = (LinearLayout) findViewById(R.id.myLayout);
  
  // need to create a view object from the xml file
  linear.addView(myXmlObject);
  </code></pre>
  
  <p>Is it possible to convert an XML resource to a view type? If so, how would I do this?</p>