title: Android add row to table on button click
body: <p>I have a TableLayout in my application. I have Two definite Rows so far. One Row has static items assigned to it, and the other has 3 spinners assigned top it.</p>
  
  <p>What I'd like to do is, add a new TableRow when ever I click on a button. So far I have the following code:</p>
  
  <pre><code>&lt;TableRow
      android:layout_width="fill_parent"&gt;
      android:stretchColumns="0,1,2"
  
      &lt;Spinner
      android:padding="3dip"
      android:gravity="left"
      android:id="@+id/Spinner1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="30dp" /&gt;
  
  
      &lt;Spinner
      android:padding="3dip"
      android:gravity="left"
      android:id="@+id/Spinner2"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="30dp" /&gt;
  
      &lt;Spinner
      android:padding="3dip"
      android:gravity="left"
      android:id="@+id/spinner3"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="30dp" /&gt;
  &lt;/TableRow&gt;
  </code></pre>
  
  <p>This is just me second row, the row that I want to add when ever I click said button. MY question is, how do I add the following row into my view, every time the user clicks the button? The values of the spinners will differ, but the variables will stay the same.</p>
  
  <p>Edit:</p>
  
  <p>More code:</p>
  
  <pre><code>        /* Find Tablelayout defined in teh XML file */
      TableLayout tl = (TableLayout) findViewById(R.id.listTable);
      /* Create a new row to be added. */
      TableRow tr = new TableRow(this);
      tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
      /* Create a Button to be the row-content. */
      Button b = new Button(this);
      b.setText("Add row");
      b.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
      /* Add Button to row. */
      tr.addView(b);
      /* Add row to TableLayout. */
  
      tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
  }
  </code></pre>
  
  <p>View changed to this:</p>
  
  <pre><code>&lt;TableRow
      android:id="@+id/copyRow"
      android:layout_width="fill_parent" &gt;
      android:stretchColumns="0,1,2"
  
      &lt;Spinner
      android:padding="3dip"
      android:gravity="left"
      android:id="@+id/Spinner1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="30dp" /&gt;
  
  
      &lt;Spinner
      android:padding="3dip"
      android:gravity="left"
      android:id="@+id/Spinner2"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="30dp" /&gt;
  
      &lt;Spinner
      android:padding="3dip"
      android:gravity="left"
      android:id="@+id/spinner3"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="30dp" /&gt;
  &lt;/TableRow&gt;
  </code></pre>
  
  <p>If It makes a difference, I'm using JellyBean 4.3 as the target API</p>