1

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="match_parent">

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

</LinearLayout>

1 Answer 1

3

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);
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.