如何制作分段ListView
我一整天都在搜索如何在 ListView 中制作这些部分。还没有找到任何东西。我浏览过许多博客,其中大多数都讨论了 CommonsWare 所采用的方法(即SectionAdapter),但在他的 GitHub 存储库中却找不到SectionAdapter.java。
这是怎么做到的呢? (即标记为 A 的部分。我不想制作首选项列表。更多关于联系人列表的内容)
I have been searching all day on how to make these sections in a ListView. Haven't found anything yet. I have been through many blogs and most of them talk about the approach CommonsWare takes (i.e. SectionAdapter) but the SectionAdapter.java is nowhere to be seen on his GitHub repo.
How can this be made? (i.e. the part marked A. I am not trying to make a Preferences list. Something more on the lines of a Contact List)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在这件事上挣扎了很多。有多种方法可以做到这一点。我发现最简单并且我推荐的一种是在列表项布局中使用分隔符视图(在获取视图中膨胀的那种),并根据是否应该有标题来更改其可见性。我使用这样的东西:
我发现这比其他适配器简单得多。我只是跟踪我想要使用变量设置分隔符的位置,并基于此我在
getView()
中setVisibility(View.VISIBLE)
。I struggled a lot on this. There are a number of ways to do this. The one I found simplest and which I recommend is using separator view in your list item layout (the one you inflate in get view) and change its visibility based on whether on not there should be a header. I use something like this:
I found this much simpler than the other adapter. I just kept track of where I wanted to have a separator using a variable and based on that I
setVisibility(View.VISIBLE)
in mygetView()
.尝试将其放在 xml 中的文本视图上:
这将使它像首选项类别,看起来更好..
Try putting this on the textview in the xml:
this will make it like preferences categories that looks much better..