CQM CQM - 1 year ago 156
Android Question

Android create and populate list layout programmatically

I can't use listview because this layout will already requires scrolling. So this leaves me at a problem: how to create my tables.

What I know:

  • The size of the JSON array

I was going to try to make every cell in XML and do a for loop in the code, but my predicament is that I can't
very well, because the
names are difficult to account for, and are integers instead of strings. (probably a problem not as large as I am making it).

So here, I know the server call will return a json array with up to 5 objects in it. How can I populate my view?

I am using a LinearLayout for each row, much like I would be preparing a custom list view in preparation.

Insight appreciated.

Answer Source

Is there a specific reason you need it to be a ListView? If not you could try a LinearLayout with a vertical orientation as the container for your list. Just put the container in your xml and you can programatically add the rows that you generate using addView().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download