• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

TableLayout programming

ateneouw

Lurker
Jan 9, 2019
1
0
My question is how do i access TableLayout as indexes.
If i do:

TableLayout table = (TableLayout) findViewById(R.id.MyTable);

i get the control in "table". But how do i access rows and colums? Or if i want to create a new row programmatically, how do i do?

Thanks in advance.
 
There's some code here which adds a new table row dynamically

https://stackoverflow.com/questions...ly-adding-tablerow-to-tablelayout-not-working

Code:
/* Find Tablelayout defined in main.xml */
TableLayout tl = (TableLayout) findViewById(R.id.SaleOrderLines);
/* Create a new row to be added. */
TableRow tr = new TableRow(this);
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
/* Create a Button to be the row-content. */
Button b = new Button(this);
b.setText("Dynamic Button");
b.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
/* Add Button to row. */
tr.addView(b);
/* Add row to TableLayout. */
//tr.setBackgroundResource(R.drawable.sf_gradient_03);
tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones