Nick
Nick

Reputation: 25

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?

Upvotes: 1

Views: 1122

Answers (2)

Lokesh Kakkar
Lokesh Kakkar

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

xandy
xandy

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

Related Questions