问题描述
是否可以/建议使用嵌套列表视图?
is it possible/advisable to have a nested listview?
即包含在另一个列表视图的一行中的列表视图?
i.e. a listView that's contained within a row of another listview?
一个例子是我的主列表显示博客文章,然后在每一行中,你会有另一个列表视图来显示每篇文章的评论(可以折叠)
an example would be where my main list is displaying blog posts, and then in each row, you'd have another list view for the comments for each post (that would be collapsible)
推荐答案
我今天遇到了同样的问题,所以我是这样做的:
I had the same problem today, so this is what I did to solve it:
我有一个 ListView,带有一个 CustomAdapter,在 customAdapter 的 getView 上,我有这样的东西:
I have a ListView, with a CustomAdapter, and on the getView of the customAdapter, I have something like this:
LinearLayout list = (LinearLayout) myView.findViewById(R.id.list_musics);
list.removeAllViews();
for (Music music : albums.get(position).musics) {
View line = li.inflate(R.layout.inside_row, null);
/* nested list's stuff */
list.addView(line);
}
所以,继续说,不可能嵌套到 ListViews,但您可以使用 LinearLayout 在一行内创建一个列表并用代码填充它.
So, resuming, It's not possible to nest to ListViews, but you can create a list inside a row using LinearLayout and populating it with code.
这篇关于android嵌套列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!