运行时添加按钮的问题

我想在程序运行时在 TableRow 中添加一些按钮, TableRow 有下面的结构:

<TableRow 
            android:layout_marginTop="100px" 
            android:gravity="bottom" 
            android:paddingTop="50px" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:id="@+id/riga1">

            <Button 
                android:textSize="32px" 
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content" 
                android:id="@+id/buttonOK2" 
                android:text="YES"
                android:onClick="setResult"/>
        </TableRow>

我的 java 代码是:

TableRow tr = (TableRow) findViewById(R.id.riga1);
        Button b = new Button(this);  
        b.setText("button 1");  
        b.setId(1);
        b.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));   
        tr.addView(b);

        Button b1 = new Button(this);  
        b1.setText("button 2");  
        b1.setId(2);
        b1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));   
        tr.addView(b1);

但现在还是不能运行,在 activity 中我只能看见 xml文件中定义的按钮。

另一个问题是如果我在相关的 TableLayout 中设置参数:

android:stretchColumns="*" 

我必须在之前提到的 TableLayout 中的 TableRow 里至少插入一个按钮,否则会在streatchColumns 附近获得一个 "division by zero error"错误。如何能让 tableRow 为空?

是不是TableRow 也需要代码写?