The way to add row to tablelayout in android.
- Find the table layout id.
- New a row for table.
- Add the view you want.( EditText for this example)
- Add the new EditText to row.
- Add the row to tablelayout.
- Done
public void touchToAddRow()
{
TableLayout tl = (TableLayout)findViewById(R.id.tableLayout);
TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams( LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
EditText et1 = new EditText(this);
et1.setId(100+rows*6+0);
rows++;
tr.addView(et1);
tl.addView(tr, new LayoutParams( LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
}

0 意見:
張貼留言