[英]What is the most efficient way to display a table in Android
I have a post to server which returns a JSONArray. 我有一个帖子到服务器,它返回一个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.
然后,我通过动态创建插入到TableLayout中的TableRows来填充TableLayout,还动态创建TextViews,之后将文本设置为JSONArray中的值。 And add the TextViews to the Rows.
并将TextViews添加到行中。
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. 没错,TableLayout的效率很低,考虑到您有100行内容,那么您必须创建100行小部件。.这非常消耗内存且创建缓慢。
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. 上面的场景应该非常适合使用ListView,您只需将JSON数组反序列化为自定义适配器即可推送到ListView。 I usually create/use a JSON-Cursor Adapter so that it can be more reusable (fits to ContentProvider as well).
我通常创建/使用JSON游标适配器,以便使其更可重用(也适合ContentProvider)。
http://developer.android.com is the most efficient way to learn android... http://developer.android.com是学习android的最有效方法。
check out this url for your result : 查看此网址以获取您的结果:
http://developer.android.com/guide/topics/ui/declaring-layout.html#CommonLayouts http://developer.android.com/guide/topics/ui/declaring-layout.html#CommonLayouts
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.