title: Adding data row dynamically
body: <p>I'm using eclipse + android SDK.</p>
  
  <p>I'm trying to create a table with data provided by sensors. I get the information correctly, by i'm having problems to make a table to show it in XML dinamically.</p>
  
  <p>This is the sensorinfo.XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:stretchColumns="1"
  android:id="@+id/SensorInfoTableLayout"&gt;
  
  
  &lt;TableRow&gt;
  
      &lt;TextView
              android:layout_column="1"
              android:text="@string/sensor_name_title"
              android:padding="3dip" /&gt;
  
      &lt;TextView
              android:layout_column="2"
              android:text="@string/sensor_type_title"
              android:padding="3dip" /&gt;
      &lt;TextView
              android:layout_column="3"
              android:text="@string/sensor_value_title"
              android:padding="3dip" /&gt;
      &lt;TextView
              android:layout_column="4"
              android:text="@string/sensor_unit_title"
              android:padding="3dip" /&gt;
  &lt;/TableRow&gt;
  
     &lt;View
      android:layout_height="4dip"
      android:background="#FF909090" /&gt;
  
  &lt;/TableLayout&gt;
  </code></pre>
  
  <p>And this is the code of my activity:</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) 
  {
      super.onCreate(savedInstanceState); 
  
      getSensorInfo();
      setContentView(R.layout.sensorinfo);
  
      setInfoByView();
  
  }
  </code></pre>
  
  <p>And</p>
  
  <pre><code>    private void setInfoByView()
  {
      /* Find Tablelayout defined in xml */
      TableLayout myTableLayout = (TableLayout)findViewById(R.id.SensorInfoTableLayout);
      /* Create a new row to be added. */
      TableRow myTableRow = new TableRow(this);
      myTableRow.setLayoutParams(new LayoutParams(
                          LayoutParams.WRAP_CONTENT,
                          LayoutParams.WRAP_CONTENT));
      /* Create a Button to be the row-content. */
      Button b = new Button(this);
      b.setText("Dynamic Button");
      b.setLayoutParams(new LayoutParams(
                          LayoutParams.WRAP_CONTENT,
                          LayoutParams.WRAP_CONTENT));
      myTableRow.setBackgroundColor(5);
      /* Add Button to row. */
      myTableRow.addView(b);
      /* Add row to TableLayout. */
      myTableLayout.addView(myTableRow,new TableLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
  }
  </code></pre>
  
  <p>THIS IS A TEST, i'm trying to include a button dinamically, if work, i will put the information i get from getSensorInfo();</p>
  
  <p>But my Activity looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/ZYuSv.png" alt="ACTIVITY IMAGE"></p>
  
  <p>What could I be doing wrong?</p>
  
  <p>All the info i found was <a href="https://stackoverflow.com/questions/1407100/dynamically-adding-and-removing-table-rows-android">THIS</a>, but the answers didn't help me.</p>