如何制作分段ListView

发布于 2025-01-07 10:32:20 字数 264 浏览 2 评论 0原文

在此处输入图像描述

我一整天都在搜索如何在 ListView 中制作这些部分。还没有找到任何东西。我浏览过许多博客,其中大多数都讨论了 CommonsWare 所采用的方法(即SectionAdapter),但在他的 GitHub 存储库中却找不到SectionAdapter.java。

这是怎么做到的呢? (即标记为 A 的部分。我不想制作首选项列表。更多关于联系人列表的内容)

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡水深流 2025-01-14 10:32:20

我在这件事上挣扎了很多。有多种方法可以做到这一点。我发现最简单并且我推荐的一种是在列表项布局中使用分隔符视图(在获取视图中膨胀的那种),并根据是否应该有标题来更改其可见性。我使用这样的东西:

<TextView
    android:id="@+id/separator"
    android:layout_width="fill_parent"
    android:visibility="gone"
    android:layout_height="wrap_content" />

我发现这比其他适配器简单得多。我只是跟踪我想要使用变量设置分隔符的位置,并基于此我在 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:

<TextView
    android:id="@+id/separator"
    android:layout_width="fill_parent"
    android:visibility="gone"
    android:layout_height="wrap_content" />

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 my getView().

ぃ弥猫深巷。 2025-01-14 10:32:20

尝试将其放在 xml 中的文本视图上:

<TextView 
style="?android:attr/listSeparatorTextViewStyle"
android:id="@+id/tv_separator"
android:visibility="gone"
/>

这将使它像首选项类别,看起来更好..

Try putting this on the textview in the xml:

<TextView 
style="?android:attr/listSeparatorTextViewStyle"
android:id="@+id/tv_separator"
android:visibility="gone"
/>

this will make it like preferences categories that looks much better..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文