如何使用android SDK将行动态添加到TableLayout?

如何使用android SDK将行动态添加到TableLayout?,android,dynamic,tablelayout,Android,Dynamic,Tablelayout,这是我的XML布局代码。我希望能够在TableLayout-tableLayout1中动态添加行。请帮忙 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match

这是我的XML布局代码。我希望能够在TableLayout-tableLayout1中动态添加行。请帮忙

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TableLayout android:id="@+id/tableLayout1" 
        android:layout_height="match_parent" 
        android:layout_width="wrap_content">
    </TableLayout>

</LinearLayout>

如果tableLayout1是您的TableLayout,则

for(int i=0;i<10;i++)
    {
        TableRow tR = new TableRow(this);
        tR.setPadding(5,5,5,5);

        TextView tV_txt1 = new TextView(this);
        TextView tV_txt2 = new TextView(this);


        tV_txt1.setText("This is the textbox1");

        tV_txt2.setText("This is the textbox2");

        tR.addView(tV_txt1);
        tR.addView(tV_txt2);

        tablelayout1.addView(tR);
    }
for(int i=0;i