Dynamically add rows to the TableLayout
<p>I am trying to add table rows dynamically...... 
Following is my java code:</p>

<pre><code>TableLayout tl = (TableLayout) findViewById(R.id.tablerow);
        /* Create a new row to be added. */
        TableRow tr = new TableRow(this);
        tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,   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.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        /* Add Button to row. */
        tr.addView(b);
        /* Add row to TableLayout. */
        tl.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
</code></pre>

<p>My XML code is</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tablerow"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" &gt;

    &lt;TableRow&gt;
        &lt;TextView
            android:id="@+id/content"
            android:singleLine="false" /&gt;
    &lt;/TableRow&gt;

&lt;/TableLayout&gt;
</code></pre>

<p>But I get error at this line:</p>

<pre><code>final TableLayout tl = (TableLayout)findViewById(R.id.tablerow);
</code></pre>

<p>Error I get is <strong>Cannot cast from view to TableLayout</strong></p>

<p>Any help will be appreciated</p>
