Как мне динамически добавлять строки в TableLayout с Android SDK? - PullRequest
1 голос
/ 09 мая 2011

это мой код компоновки 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>

1 Ответ

3 голосов
/ 09 мая 2011

Если 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);
    }
...