列表视图中 itemview 的表格布局 android 性能
我正在尝试使用列表视图和表格视图开发 Facebook 类型的提要。每行在列表视图中都有带有评论的提要帖子。我将 feed 的数据对象存储在数组列表中。
class FeedPost{
String username;
String imageUrl;
String feedpostText;
ArrayList<Comment> comments;}
在我的 get 视图中,我这样做
public View getView(final int position, View convertView, ViewGroup parent) {
feedItem = FeedItems.get(position);
convertView = layoutInflater.inflate(R.layout.feed_main, null);
TableLayout mainFeedLayout = (TableLayout) convertView
.findViewById(R.id.blogFeedTableLayout);
TextView displayName = (TextView) convertView
.findViewById(R.id.feed_username);
TextView description = (TextView) convertView
.findViewById(R.id.comment_text);
// Set the text to the texview
.
.
.
// Adding comments to the feed
for (int i = 0; i < feedItem.feedComments.size(); i++) {
mainFeedLayout .addView(addComment(
convertView, feedItem.feedComments.get(i)));
}
}
再次在 addcomments 函数中,我正在膨胀评论布局,以便可以将其添加到表布局中
因此,对于要在列表视图中显示的单个提要,我正在检查每个提要项目评论并在提要中显示它们。这确实是痛苦且缓慢的。
我尝试使用静态持有者进行布局,而不是每次都膨胀它们。同样,这也不起作用。如果有多个不同的视图,那么我会尝试 commonsguy 的“SackOfViewsAdapter”。但实际上这并不是不同的观点。
我认为 facebook 使用 webview 并渲染 html 来显示用户的提要。使用 android 本机布局和代码执行相同操作的最佳方法是什么?您能帮我建议显示此类复杂数据的最佳方法吗?
I am trying to develop a facebook kind of feeds using list view and table view. Each row has the feed post with comments in the list view. I am storing the data objects of feed in the array list.
class FeedPost{
String username;
String imageUrl;
String feedpostText;
ArrayList<Comment> comments;}
In my get view i am doing like this
public View getView(final int position, View convertView, ViewGroup parent) {
feedItem = FeedItems.get(position);
convertView = layoutInflater.inflate(R.layout.feed_main, null);
TableLayout mainFeedLayout = (TableLayout) convertView
.findViewById(R.id.blogFeedTableLayout);
TextView displayName = (TextView) convertView
.findViewById(R.id.feed_username);
TextView description = (TextView) convertView
.findViewById(R.id.comment_text);
// Set the text to the texview
.
.
.
// Adding comments to the feed
for (int i = 0; i < feedItem.feedComments.size(); i++) {
mainFeedLayout .addView(addComment(
convertView, feedItem.feedComments.get(i)));
}
}
Again in addcomments functions i am inflating the comment layout so that it can be added to the table layout
So for a single feed to be displayed in the list view, I am checking the each feed item for comments and displaying them in the feed. This is really painful and slow.
I tried using the static holders for layouts instead of inflating them each time. Again that didnt work also. If there are mulitple different views, then i would have tried "SackOfViewsAdapter " of commonsguy. But actually it is not different views.
I think facebook uses the webview and render the html for the showing the feeds of the user. What is the best way to do the same using the android native layout and code. Can you help me in suggesting the best method to use for showing this kind of complex data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我的实现。我删除了很多视图,只是想展示如何回收远程图像视图(来自 Ignition / Droid-fu)。
This is my implementation. I removed a lot of views, just wanted to show how a remote image view (from Ignition / Droid-fu) could be recycled.
两件事:重新使用视图并创建一个异步任务来加载提要(将提要和 for 移至任务)。这样你就不会阻塞 UI 线程。
我命令重新使用视图很容易。像这样的事情:
对于 asynctask,我会将您想要更新的视图传递给 asynctask,并让任务在完成时更新视图。
Two things: Re use views and make an Asynctask to load the feed (Move the feed and the for to the task). That way you won't choke the UI thread.
I order to re use the views its easy. Something like this:
For the asynctask, I would pass the view that you want to update to the asynctask and let the task update the view when is done.