How to set (Text)View attributes programmatically?
<p>I am desperately trying to set TextView attributes of cells within a table programmatically but can't get this to work! Whenever I set layout properties, the field will simply not appear (but not give any error or exception). I boilded this down to this simple example:</p>

<pre><code>package mmo.application.listpro;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class Test extends Activity
{
    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TableLayout table = new TableLayout(this);
        TableRow row = new TableRow(this);
        for (String label: new String[] {"field1", "field2", "field3"}) {
            TextView tv = new TextView(this);
            tv.setText(label);
//          LinearLayout.LayoutParams lp = 
//              new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 
//                                            LinearLayout.LayoutParams.WRAP_CONTENT);
//          lp.setMargins(2, 2, 2, 2);  // left/top/right/bottom
//          tv.setLayoutParams(lp);
            row.addView(tv);
        }
        table.addView(row);
        setContentView(table);
    }
}
</code></pre>

<p>This will show three fields, but when you uncomment the five commented line, then NOTHING will appear. Why is that so? Why does setting layout parameters cause my TextView's to not appear? I'm stuck! What am I missing?</p>

<p>Michael</p>

<p>PS.: here's the manifest, if some kind soul quickly wants to try this out:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="mmo.application.listpro" android:versionCode="1" android:versionName="Development"&gt;
    &lt;application 
        android:icon="@drawable/icon" 
        android:label="@string/app_name"
        android:debuggable="true"&gt;
        &lt;activity
            android:label="test" 
            android:name=".Test"
            android:screenOrientation="portrait"&gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;
                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
    &lt;/application&gt;
    &lt;uses-sdk android:targetSdkVersion="8" android:minSdkVersion="8" /&gt;
&lt;/manifest&gt; 
</code></pre>
