简体   繁体   中英

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM