简体   繁体   English

在Android中显示表格的最有效方法是什么

[英]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.

相关问题 在Android用户界面中旋转和显示图像的最有效方法是什么? - What is the most efficient way to rotate and display an image in an Android UI? 使用Android相机的最有效方法是什么? - What is the most efficient way to work with the Android camera? 在android中,比较两个文件以确定它们是否相同的最有效方法是什么? - In android, what is the most efficient way to compare two files to determine if they are identical? Android最有效的保存和加载图像的方法是什么? - Android what's the most efficient way to save and load images? 什么是最有效的(电池)重复动作在android中的方法? - what is the most efficient(battery) way to repeat an action in android? 在Android的SharedPreferences中存储数组的最有效方法是什么? - What is the most efficient way to store an array in SharedPreferences in Android? 在Android应用中流视频的最有效方法是什么 - what is the most efficient way to stream videos in android app 在Android中保存游戏状态的最有效方法是什么? - What is the most efficient way to save game status in Android? 在Android中运行Cursor的最有效方法是什么? - What's the most efficient way to run over a Cursor in Android? 在Android中重复写入XML文件的最有效方法是什么? - What is the most efficient way of repeatedly writing to an XML file in Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM