android - Setting number of columns programmatically in TableLayout -
i have xml layout contains tablelayout unknown number of tablerows... number of rows established durin runtime, know though want 2 columns... have couple of questions regarding :
- - there way set whole tablelayout have 2 columns ?
- there way programmatically give id (during runtime) created tablerows placed within tablelayout, can reference them later on other parts of software ?
you can build table rows via xml parts , layoutinflater. had table_cell.xml:
<textview android:id="@+id/text" android:text="woot" />
and table_row.xml (unless you're doing fancy tablerow, may not need put in it's own xml file, , instead create programmatically. result same):
<tablerow />
assuming tablelayout reference called "table", this:
tablelayout table = (tablelayout)findviewbyid(r.id.table); layoutinflater inflater = getlayoutinflater(); for(int = 0; < 5; i++) { tablerow row = (tablerow)inflater.inflate(r.layout.table_row, table, false); view v = (view)inflater.inflate(r.layout.table_cell, row, false); row.addview(v); v = (view)inflater.inflate(r.layout.table_cell, row, false); row.addview(v); // can store reference `row` here later use table.addview(row); }
with technique, can still set layout in xml, making easier read/organize/edit, , still have programmatic control on how many columns , rows in table. can store references each table row later use.
Comments
Post a Comment