【发布时间】:2012-01-02 15:28:10
【问题描述】:
我正在尝试使用列表视图和表格视图开发一种 facebook 类型的提要。每行在列表视图中都有带有 cmets 的提要帖子。我将 feed 的数据对象存储在数组列表中。
class FeedPost{
String username;
String imageUrl;
String feedpostText;
ArrayList<Comment> comments;}
在我看来,我正在这样做
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)));
}
}
在 addcmets 函数中,我再次夸大了评论布局,以便可以将其添加到表格布局中
因此,对于要在列表视图中显示的单个提要,我正在检查每个提要项目中的 cmets 并将它们显示在提要中。这真的很痛苦而且很慢。
我尝试使用静态支架进行布局,而不是每次都膨胀它们。同样,这也不起作用。如果有多种不同的观点,那么我会尝试 commonsguy 的“SackOfViewsAdapter”。但实际上并没有不同的看法。
我认为 facebook 使用 webview 并渲染 html 来显示用户的提要。使用 android 本机布局和代码执行相同操作的最佳方法是什么。您能帮我推荐用于显示这种复杂数据的最佳方法吗?
【问题讨论】:
-
回收视图应该更快,对吧?我将类扩展为 ArrayAddapter
-
由于表格布局因内容而异,因此很难回收。请考虑 facebook feedview,我认为回收视图并不容易,因为每个提要的评论会根据帖子而有所不同。有什么建议吗?
-
你错了,你可以回收很多。现在您必须为每个列表项实例化 TextViews。如果你回收,那么你只需要为每个列表项设置文本。请阅读有关回收的更多信息,并亲自了解它在调试期间的工作原理。
标签: android performance listview tableview