Nick Nick - 20 days ago 10
Android Question

What is the most efficient way to display a table in Android

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?

Answer

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).

Comments