我有一个包含一些头的列表视图,用于分隔列表项。我们的想法是让它的行为类似于jellybean中的联系人应用程序,带有字母首字母的部分标题。我使用的方法是在我的list_item.xml中有一个额外的文本视图,我根据下一个字母是否需要新的分隔符来动态隐藏或显示该视图。
问题是,无论何时添加节标题,它都可以与下一个客户端条目一起单击。所以这就像是
A
_____
AllyTHis整个列表单元格将可由用户选择。我只希望Ally被选中,而标题是不可选择的。我该怎么做呢?
发布于 2013-08-08 05:46:39
这看起来就是您想要实现的目标:http://blog.peterkuterna.net/2011/05/pinned-header-listview-as-in-contacts.html
可以从here下载定制的PinnedHeaderListView (这是他在博客中提到的Devoxx2010时间表应用程序)
发布于 2013-08-08 13:53:33
解决方案1,您可以使用为我解决的Amazing List View Library.this。你可以参考它的代码,它不是很长。
方案二,在正常的listview中添加header,如下所示:
itemheader.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/daily_title"
android:textColor="#545454"
android:text="04/16"
android:paddingLeft="10dp"
android:gravity="center_vertical"
android:textSize="10sp"
android:id="@+id/header"/>item_rows.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/ArticleList.item"
android:background="@drawable/list_item_bg"
android:orientation="vertical">
<include
android:layout_width="fill_parent"
android:layout_height="24dp"
layout="@layout/itemheader" />然后你只需要注意哪一行需要显示标题。
发布于 2013-08-14 17:28:52
实现这一点的一种方法是使用实现SectionIndexer的自定义ArrayAdapter。在这里可以找到一个很好的简单的教程:
http://twistbyte.com/tutorial/android-listview-with-fast-scroll-and-section-index
https://stackoverflow.com/questions/17998654
复制相似问题