1

I just want to add new rows at run time, and I tried using following codes..

java file ::>

TableLayout caseTable = (TableLayout) findViewById(R.id.caseTable);
TableRow caseRow = new TableRow(this);
caseRow.setOrientation(TableRow.VERTICAL);
EditText name = new EditText(this);
name.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
name.setText("Name __");
caseRow.addView(name);
caseTable.addView(caseRow,new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));

xml file ::>

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id="@+id/caseTable"
    android:stretchColumns="0,1,2,3">
    <TableRow>
        <TextView android:text="Case" />
        <TextView android:text="Details" />
    </TableRow>
</TableLayout>

I want to add new rows below the existing one. I get the code from here at stackOverFlow. But it didn't work. Thank you.

1 Answer 1

1

Just Simply Use The below code to add TableRow Programatically, perviously it is not working because you are trying to add TableLayout parameter to your EditText.

        TableLayout caseTable = (TableLayout) findViewById(R.id.caseTable);
        TableRow caseRow = new TableRow(this);
        caseRow.setOrientation(TableRow.VERTICAL);
        EditText name = new EditText(this);
        //name.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
        name.setText("Name __");
        caseRow.addView(name);
        caseTable.addView(caseRow,new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
Sign up to request clarification or add additional context in comments.

1 Comment

I get this from here at stackOverflow. Anyway Thank you. :)

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.