Programmatically Adding Items From A List To A Tablelayout
I have an Android project I am working on. I am fairly new to Android Development so I have some code in a MainActivity.java file that I am working on Creating a Table Layout for
Solution 1:
You are pretty close but What you have to do is:
- Remove your TableRow from your xml.
- Always create a new TableRow in a loop.
- All your TextViews need a layout params set by
setLayoutParams(new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT))
; - Add table row to a table layout also in a loop
- I would say MATCH_PARENT would be better for each table row width
The other way to do it would be to make an xml file with and it's textViews inside of it. Inflate the xml with LayoutInflater.from(context).inflate(...), fill all 3 textviews finding them by id and add this inflated tableRow to a tableLayout
Post a Comment for "Programmatically Adding Items From A List To A Tablelayout"