如何生成与头以上的部分路段一个ListView?路段、部分、ListView

2023-09-12 07:59:13 作者:酸奶suannai;

我要生成一个的ListView ,有一些分隔一些条目之间,喜欢的话可以在一些物业部分可以看出。请参见下面的例子。我尝试生成一个列表,它由一些 textviews 其次是看中分频器解释列表的下一个部分之一,然后又有些文本观点。如何才能做到这一点?我想到了创建不同的意见,添加到列表中?这是要走的路?

I want to generate a ListView that has some dividers between some of the entries, like it can be seen in some of the property sections. See the example below. I try to generate a List that consists of some textviews followed by one of the fancy dividers explaining the next part of the list and then again some text views. How can this be done? I thought about creating different views to add to the list? Is this the way to go?

推荐答案

我得到了一个解决方案。我不知道这是否是最好的之一。

I got a solution. I don't know if it is the best one.

我使用ArrayAdapter对于如在此所描述的列表tutorial.在适配器类我检查,如果在getView方法的位置是正常行,那我膨胀的行布局。如果它是在第一行从一个新的组我膨胀标题布局这是一个正常的行加的组标题它上面。

I use a custom adapter derived from ArrayAdapter for the list as described in this tutorial. In the adapter class I check if the position in the getView method is a normal row, then I inflate the row layout. If it is the first row from a new group I inflate a headline layout that is a normal row plus the group headline above it.

如果你不想混了头到你的行之一。考虑以下方案:

If you don't want to mix the header into one of your rows. Consider the following solution:

您可以覆盖这两种方法getItemViewType和getViewTypeCount. 您现在有一个可以显示不同行的列表。您需要检查预期的视图类型在getView方法的项目和膨胀取决于其不同的布局。

You can overwrite the two methods getItemViewType and getViewTypeCount. You now have a list that can display different rows. You need to check the expected view type for the item in the getView Method and inflate different layouts depending on it.

该列表将处理回收你的方式,它将返回唯一正确的循环意见,您的getView方法,这意味着如果recycleView不为空,可以用来显示你当前的电池。

The list will handle the recycling for you in a way that it will return only correct recycle views to your getView method, this means if the recycleView is not null it can be used to display your current cell.