Java 在Android中向TableLayout动态添加行

Java 在Android中向TableLayout动态添加行,java,android-layout,tablelayout,Java,Android Layout,Tablelayout,我正在开发一个应用程序,该应用程序需要将行动态添加到包含2列的表中。下面是我正在使用的代码。。。。我得到一个ForceClose错误。。。plss帮助 <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/table" android:layout_width="fill

我正在开发一个应用程序,该应用程序需要将行动态添加到包含2列的表中。下面是我正在使用的代码。。。。我得到一个ForceClose错误。。。plss帮助

<?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TableRow 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
>
<Button android:id="@+id/b1" />
</TableRow>
    </TableLayout>
tb.addViewtr,lp;他有一只虫子。。Lp是布局参数,已设置为TableRow,因此只需使用tb.addViewtr;而不是tb.addViewtr,lp

            TableLayout tb=(TableLayout)findViewById(R.id.table);
    TableRow tr=new TableRow(getBaseContext());
    Button b1=(Button)findViewById(R.id.b1);
    LayoutParams lp=new         LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);

    tr.setLayoutParams(lp);
    b1.setLayoutParams(lp);
    b1.setText("I NEED HELP ! SOS ");

    tr.addView(b1);
    tb.addView(tr,lp);