开发者

how do i dynamically add rows to a TableLayout with android SDK?

开发者 https://www.devze.com 2023-03-04 17:01 出处:网络
this is my XML layout code. i want to be able to dynamically add rows the TableLayout - tableLayout1. please help

this is my XML layout code. i want to be able to dynamically add rows the TableLayout - tableLayout1. please help

<?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="m开发者_StackOverflowatch_parent">

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

</LinearLayout>


If tableLayout1 is your TableLayout, then

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);
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消