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.
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));
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments