title: Adding views programmatically with a xml layout
body: <p>I want to programmatically add a view to ScrollView that is apart of a Fragment layout.</p>
  
  <p>I have attempeted the following code:</p>
  
  <pre><code>public class MessageDetail extends Fragment {
  
      View layout;
      TextView messageText;
      Conversation conversation;
      List&lt;Message&gt; messages;
      LayoutInflater inflater;
      ViewGroup container;
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          this.inflater = inflater;
          this.container = container;
          layout = inflater.inflate(R.layout.messenger_detail, container,
                  false);
          messageText = (TextView) layout.findViewById(R.id.tvMessage);
  
          return layout;
  
      }
  
      public void loadConversation(Conversation conversation) {
  
          messageText.setText(conversation.getSubject());
  
          LinearLayout messagesView = (LinearLayout)layout.findViewById(R.id.llMessageDetail);
  
          LinearLayout messageBody = new LinearLayout(getActivity());
          View body = inflater.inflate(R.layout.messagebody, container);
  
  
          messagesView.addView(body);
  
      }
  
  }
  </code></pre>
  
  <p><strong>messagebody.xml</strong></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/llMessageBody"
      android:layout_width="fill_parent"
      android:layout_margin="5dp"
      android:layout_height="200dp"
      android:background="#353535"
      android:orientation="vertical" &gt;
      &lt;TextView 
          android:id="@+id/tvMSBodyFrom"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="20dp"
          android:text="Research Station:"
          android:textColor="#FFFFAA"
          /&gt;
  &lt;ImageView 
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:background="@drawable/tomatohigh"
      /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>message_detail.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="#d3d6da"
      android:orientation="vertical" &gt;
  
      &lt;LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="100dp"
          android:background="#FFAA00" &gt;
  
          &lt;TextView
              android:id="@+id/tvMessage"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="center"
              android:layout_marginLeft="20dp"
              android:text="Select a Message:"
              android:textColor="#353535"
              android:textSize="30dp" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;ScrollView
          android:id="@+id/svMessageDetail"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:background="#9900AA"
          android:minHeight="300dp" &gt;
  
          &lt;LinearLayout
              android:id="@+id/llMessageDetail"
              android:layout_width="fill_parent"
              android:orientation="vertical"
              android:layout_height="wrap_content" &gt;
  
          &lt;/LinearLayout&gt;
      &lt;/ScrollView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>The final implementaion would see me loop through a list of messages and add the a view with the message_body layout and change each part of the layout to the correct values of each message</p>
  
  <p>Any ideas how to achieve this?</p>