下面的文章是我在搜索SectionsHeaders for Android 的时候 StackOverflow上边的好几个答案都说到的一篇文章(相比应该很经典)。

原文地址应该是这里:http://thebogles.com/blog/2010/02/section-headers-for-android-listviews/ (可惜我打不开,原文具体内容不得而知,遗憾)

下面是我从http://bbs.hidroid.net/thread-1069-1-1.html这里摘录的:

When building the Android version of the iLike Concert app, I wanted to have day headers for the concert list.
This was easy on the iPhone; sections are built into the oUITableView class.  
Surprisingly, the ListView class in Android doesn't provide any corresponding functionality, as of Android 2.1.
Jeff Sharkey's SeparatedListAdapterprovides one way to get this functionality; it glues together a numberof individual adapters for each section into an overall list.
In my case, I had one SimpleCursorAdapter for the whole list, so I didn't want to break it into individual adapters just to displaysections.
Instead, I made the header a part of the list cell layout, and hid the header on the rows where I didn't want to display it. The headers look as follows:

My layout was like as follows; note the use of the explicit background color and textColorHighlight in the date header to preventit from appearing as selected.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/date_header" android:textSize="20px" android:textStyle="bold" android:textColor="#000" android:textColorHighlight="#000" android:background="#DDD" android:visibility="gone" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="77px" android:gravity="center_vertical" android:orientation="horizontal"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="100px" android:layout_height="75px" android:gravity="center_vertical|center_horizontal" android:orientation="horizontal"> <ImageView android:id="@+id/image" android:layout_width="75px" android:layout_height="75px"/> </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="vertical"> <TextView android:id="@+id/title" android:textSize="20px" android:textStyle="bold" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <TextView android:id="@+id/description" android:textSize="14px" android:layout_width="fill_parent" android:layout_height="wrap_content"/> </LinearLayout> </LinearLayout>
</LinearLayout>

The view binder assumes a function called isHeaderVisible to decide whether the header should be visible for the current row in the cursor;implement as appropriate for your application. (For example, ourapplication displays a header whenever the date of the current row isdifferent from the previous row.)

SimpleCursorAdapter listAdapter = new SimpleCursorAdapter(mContext, R.layout.list_item, mEventsCursor, new String[] {"artist_75x75_image_url", "artist_name", "venue_name", "event_date_string" }, new int[] {R.id.image, R.id.title, R.id.description, R.id.date_header }); final int nDateIndex = mEventsCursor.getColumnIndex("event_date_string"); listAdapter.setViewBinder( new SimpleCursorAdapter.ViewBinder() { public boolean setViewValue(View view, Cursor cursor, int
columnIndex) { if (columnIndex == nDateIndex) { if (isHeaderVisible(cursor)) { view.setVisibility(View.VISIBLE); prevDate = dateString; ((TextView) view).setText(dateString); } else { ((TextView) view).setText(""); view.setVisibility(View.GONE); } return true; } return false; } });

转载于:https://www.cnblogs.com/jeriffe/articles/2757235.html

【转】Sections Headers for Android ListViews相关推荐

  1. Android 使用开源库StickyGridHeaders来实现带sections和headers的GridView显示本地图片效果...

    转载请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/20481185),请尊重他人的辛勤劳动成果,谢谢! 大家好! ...

  2. stetho 调试数据库_stetho是适用于android应用程序的最佳调试工具

    stetho 调试数据库 As Android developers, our development life often involves integrating API or web servi ...

  3. ldflags android,Android 开发手记一 NDK编程实例

    Android开发手记一 ---- NDK编程实例 在Android上,应用程序的开发,大部分基于Java语言来实现.要使用c或是c++的程序或库,就需要使用NDK来实现.NDK是Native Dev ...

  4. Android Native 代码NDK开发学习笔记

    引用:http://www.kunli.info/2011/08/21/android-native-code-study-note/ JNI,全称Java Native Interface,是用于让 ...

  5. Android入门知识全套笔记

    安装apk: 开发完成之后,需要buildAPK,再次发送才能运行. adb install -r (apk完整路径) 安装在第三方app 系统级app需要把打包好的apk,浦西 卸载apk:adb ...

  6. Kotlin第五章: android网络编程

    1. Android网络编程 OkHttp OkHttp是一个高效的HTTP客户端,它的横空出世,让其他的网络请求框架都变得黯然失色. Retrofit Retrofit是一个基于OkHttp的RES ...

  7. android 仿qq好友列表分组效果及联系人分组效果

     历史记录仿QQ好友列表的动态效果 以及联系人的分组效果 QQ朋友分组的功能做的不错,大家都很认可,那么到底他的分组并且滑动的时候,标题能停留在顶部是如何实现的呢?今天从网上搜索了一下资料,自己运行了 ...

  8. Android框架源码分析——从设计模式角度看 Retrofit 核心源码

    Android框架源码分析--从设计模式角度看 Retrofit 核心源码 Retrofit中用到了许多常见的设计模式:代理模式.外观模式.构建者模式等.我们将从这三种设计模式入手,分析 Retrof ...

  9. Android C/C++开发指南

    Android C/C++开发指南 1.Android C/C++简介 众所周知,Android作为目前主流的移动终端领域的开发平台,其主要的开发语言就是JAVA.Android借助于JAVA高效.灵 ...

最新文章

  1. Docker火遍全球!Docker(Inc)这家公司却要死了???
  2. Android中Spinner下拉列表(使用ArrayAdapter和自定义Adapter实现)
  3. Matlab绘制小波尺度函数和小波函数
  4. github创建项目,并提交本地文件
  5. 运河杯交通违章 运行不起来
  6. mysql 8.0 重置数据库,Mysql 8.0安装及重置密码问题
  7. easyui input输入框的限制和校验条件
  8. WebService原理浅析
  9. 腾讯社交广告大赛总结
  10. matlab常用开头,在MATLAB编辑中,以“”开头的表示()。
  11. ​PHP现在不好找工作是真的吗?
  12. play框架在idea开发工具上的简单配置
  13. 有感于董洁为子找幼儿园因不是外籍被拒 怪自己“不争气”
  14. 分析DLL搜索顺序劫持的原理
  15. 2017最新PHP面试题
  16. 微信小程序+.NET(十五) 小程序录音无法播放
  17. Docker 搭建「个人网盘」,放弃 Pandownload!
  18. 目标检测算法(传统基于深度学习的)
  19. 中国象棋软件-引擎实现(七)测试程序
  20. OFweek(第二届)中国人工智能产业大会AI+医疗论坛成功举办

热门文章

  1. jQuery 学习-DOM篇(二):jQuery 在 DOM 内部插入元素
  2. android 内核裁剪概述,Android内核的编译与裁剪
  3. elementui 表格格式化
  4. vs code快捷键修改为idea快捷键
  5. Jupyter notebook基础教程(启动,汉化,操作)
  6. 【poj3263】Tallest Cow(差分数组)
  7. lenet5卷积神经网络_tensorflow图像识别入门实战:使用LeNet5模型实现猫狗分类
  8. p71_文件传送协议FTP
  9. OpenGL基础11:空间
  10. 51nod-1135:原根