title: Programmatically create multiple LinearLayouts
body: <p>I am attempting to create multiple instances of a linearLayout.  I created my layout file (Below).  I put it in its own layout file and from another file (main_activity.xml) I would like to add a dynamic number of Linear Layout instances within a scroll view.  I know that I can programatically create the same linearlayout in my java code and loop through it but I would rather not (for two main reasons)</p>
  
  <ol>
  <li>Creating massive layouts in my java class is starting to make my code look messy :).</li>
  <li>I like the paradigm of having my layouts in XML and my logic in Java.</li>
  </ol>
  
  <p>Is it possible for me to keep my logic in java and then just dynamically create/instantiate multiple "instances" of my Linear layout.  My guess is that there is a simple solution but my newbie status is clouding my ability to solve it.  For some reason my java code can find the LinearLayout but is not able to find the first TextView(@+id/submittedBy).  </p>
  
  <p>Thank you very much,
  Craig</p>
  
  <p>Java Logic</p>
  
  <pre><code>  ScrollView sv = (ScrollView) findViewById(R.id.existingCommentsScrollView);
      //DEBUGGING LOOP- REMOVE ME
      for(int i=0;i&lt;30;i++){
          LinearLayout ll = (LinearLayout)findViewById(R.id.existingCommentLinearLayout);
  
          TextView submittedByTextView = (TextView) findViewById(R.id.submittedBy);
          submittedByTextView.setText("Craig " +i);
  
          TextView submittedDate = (TextView) findViewById(R.id.dateField);
          submittedDate.setText("SubmittedDate " +i);
  
          RatingBar showRating = (RatingBar) findViewById(R.id.userShowRating);
          showRating.setRating(3);
  
          RatingBar soundRating = (RatingBar) findViewById(R.id.userSoundRating);
          soundRating.setRating(1);
  
          EditText commentText = (EditText) findViewById(R.id.userCommentEditText);
          commentText.setText("THIS IS WHERE MY TEXT GOES FOR "+i+" I could add more too");
  
          sv.addView(ll);
      }
      sv.refreshDrawableState();
  </code></pre>
  
  <p>Layout:</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="@drawable/linear_layout_border"
  android:orientation="vertical"
  android:theme="@android:style/Theme.NoTitleBar.Fullscreen" &gt;
  
  &lt;RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="#000000"
      android:paddingBottom="4dp"
      android:paddingLeft="4dp"
      android:paddingRight="4dp"
      android:paddingTop="4dp"
      android:theme="@android:style/Theme.NoTitleBar.Fullscreen" &gt;
  
      &lt;TextView
          android:id="@+id/submittedBy"
          android:layout_width="100dp"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:gravity="center_horizontal"
          android:inputType="none"
          android:paddingBottom="1dp"
          android:paddingLeft="4dp"
          android:paddingRight="10dp"
          android:paddingTop="1dp"
          android:text="NameGoesHere"
          android:textColor="#E6E6E6"
          android:textSize="8sp" /&gt;
  
      &lt;TextView
          android:id="@+id/dateField"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_toRightOf="@id/submittedBy"
          android:ems="10"
          android:paddingBottom="1dp"
          android:paddingLeft="4dp"
          android:paddingRight="10dp"
          android:paddingTop="1dp"
          android:text="DateGoesHere"
          android:textColor="#E6E6E6"
          android:textSize="8sp" /&gt;
  &lt;/RelativeLayout&gt;
  
  &lt;RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="#000000"
      android:paddingBottom="4dp"
      android:paddingLeft="4dp"
      android:paddingRight="4dp"
      android:paddingTop="4dp"
      android:theme="@android:style/Theme.NoTitleBar.Fullscreen" &gt;
  
      &lt;TextView
          android:id="@+id/userShowRatingTextView"
          android:layout_width="100dp"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:gravity="center_horizontal"
          android:inputType="none"
          android:paddingBottom="1dp"
          android:paddingLeft="4dp"
          android:paddingRight="10dp"
          android:paddingTop="1dp"
          android:text="Show Rating"
          android:textColor="#E6E6E6"
          android:textSize="8sp" /&gt;
  
      &lt;RatingBar
          android:id="@+id/userShowRating"
          style="?android:attr/ratingBarStyleSmall"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_toRightOf="@id/userShowRatingTextView" /&gt;
  &lt;/RelativeLayout&gt;
  
  &lt;RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="#000000"
      android:paddingBottom="4dp"
      android:paddingLeft="4dp"
      android:paddingRight="4dp"
      android:paddingTop="4dp"
      android:theme="@android:style/Theme.NoTitleBar.Fullscreen" &gt;
  
      &lt;TextView
          android:id="@+id/userSoundRatingTextView"
          android:layout_width="100dp"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_toRightOf="@id/userShowRating"
          android:gravity="center_horizontal"
          android:inputType="none"
          android:paddingBottom="1dp"
          android:paddingLeft="4dp"
          android:paddingRight="10dp"
          android:paddingTop="1dp"
          android:text="Sound Rating"
          android:textColor="#E6E6E6"
          android:textSize="8sp" /&gt;
  
      &lt;RatingBar
          android:id="@+id/userSoundRating"
          style="?android:attr/ratingBarStyleSmall"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_toRightOf="@id/userSoundRatingTextView" /&gt;
  &lt;/RelativeLayout&gt;
  
  &lt;RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content" &gt;
  
      &lt;EditText
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/editText2"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="#000000"
          android:inputType="none"
          android:paddingBottom="4dp"
          android:paddingLeft="4dp"
          android:paddingRight="4dp"
          android:paddingTop="4dp"
          android:text="Comment Goes Here"
          android:textColor="#E6E6E6"
          android:textSize="12sp"
          android:theme="@android:style/Theme.NoTitleBar.Fullscreen" &gt;
  
          &lt;requestFocus /&gt;
      &lt;/EditText&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p></p>