如何在某些部分上方生成带有标题的 ListView? [英] How to generate a ListView with headers above some sections?

查看:21
本文介绍了如何在某些部分上方生成带有标题的 ListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想生成一个 ListView,它在某些条目之间有一些分隔符,就像在某些属性部分中可以看到的那样.请参阅下面的示例.我尝试生成一个 List,它由一些 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 派生的自定义适配器对于此教程中所述的列表.在适配器类中,我检查 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:

您可以覆盖两种方法 getItemViewTypegetViewTypeCount.您现在有一个可以显示不同行的列表.您需要在 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.

这篇关于如何在某些部分上方生成带有标题的 ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆