how to generate dynamic textview in a tablerow or tablelayout in android?
<p>I have a problem with the following code:</p>

<pre><code>TextView[] tx = new TextView[10];
TableRow[] tr = new TableRow[10];
final TableLayout tl = (TableLayout)findViewById(R.id.maintable);
for(i = 0; i &lt; 10; i++)
            {
                tx[i] = new TextView(TransactionsActivity.this);
                tx[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
                tx[i].setText(Dates1);
                tr[i] = new TableRow(TransactionsActivity.this);
                tr[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
                tr[i].addView(tx[i]);
                tl.addView(tr[i], new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
            }
</code></pre>

<p>What I am trying to do is to dynamically add textview to a table row or layout. But this code does nothing when I run it, no errors though.</p>

<p>My XML code is as follows:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@drawable/energy"&gt;
   &lt;ScrollView
    android:id="@+id/scrllvwNo1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"&gt;
  &lt;RelativeLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"&gt;
  &lt;!--  Screen Design for VIDEOS --&gt;
  &lt;TextView android:id="@+id/textview1"
              android:text="Transactions page"
              android:padding="15dip"
              android:textSize="18dip"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"/&gt;
  &lt;Button
              android:id="@+id/button"
              android:text="Clear Transactions"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_toRightOf="@id/textview2"
              android:layout_below="@id/textview1"/&gt;
  &lt;TextView android:id="@+id/textview2"
              android:text=""
              android:padding="15dip"
              android:textSize="18dip"
              android:layout_width="0dip"
              android:layout_height="0dip"
              android:layout_centerHorizontal="true"/&gt;          
  &lt;Button android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Get Transactions"
            android:layout_toLeftOf="@id/textview2"
            android:layout_alignTop="@id/button"/&gt;          
  &lt;TextView android:id="@+id/textview"
              android:text=""
              android:padding="0dip"
              android:textSize="0dip"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_below="@id/button"/&gt;

&lt;HorizontalScrollView android:id="@+id/horz"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:layout_below="@id/textview"&gt;            
  &lt;TableLayout android:id="@+id/maintable" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="4"
    android:layout_below="@id/horz"&gt;

    &lt;TableRow&gt;
        &lt;TextView
            android:id="@+id/textview1"
            android:layout_column="1"
            android:text="Date"
            android:padding="15dip" /&gt;
        &lt;TextView
            android:id="@+id/textview2"
            android:layout_column="2"
            android:text="Device"
            android:layout_toLeftOf="@id/textview1"
            android:padding="15dip" /&gt;
        &lt;TextView
            android:id="@+id/textview3"
            android:layout_column="3"
            android:text="Access Type"
            android:layout_toLeftOf="@id/textview2"
            android:padding="15dip" /&gt;
        &lt;TextView
            android:id="@+id/textview4"
            android:layout_column="4"
            android:text="Area"
            android:layout_toLeftOf="@id/textview3"
            android:padding="15dip" /&gt;                        
    &lt;/TableRow&gt;

    &lt;View
        android:layout_height="2dip"
        android:background="#FF909090" /&gt;

&lt;/TableLayout&gt;
&lt;/HorizontalScrollView&gt;
&lt;/RelativeLayout&gt;
&lt;/ScrollView&gt;
&lt;/RelativeLayout&gt;
</code></pre>
