Reputation: 25
I have a post to server which returns a JSONArray. I then populate a TableLayout by dynamically creating TableRows which get inserted into the TableLayout, and also dynamically create TextViews after which I set the text to values from the JSONArray. And add the TextViews to the Rows.
This does work. Although it seem terribly insufficient and I would really like a more elegant solution.
Any suggestions?
Upvotes: 1
Views: 1122
Reputation: 11
http://developer.android.com is the most efficient way to learn android...
check out this url for your result :
http://developer.android.com/guide/topics/ui/declaring-layout.html#CommonLayouts
Upvotes: 1
Reputation: 27411
You are right, TableLayout is very inefficient, consider you have 100 rows of content, then you have to create 100 rows of widgets.. which is very memory consuming + slow in creation.
Above scenario should be a perfect fit for using ListView, you can simply de-serialize your JSON Array into a custom Adapter to push to the ListView. I usually create/use a JSON-Cursor Adapter so that it can be more reusable (fits to ContentProvider as well).
Upvotes: 4