介绍
在安卓2.1及更高版本中使用ListView十分方便。固定部分是header视图,当所有项目均不可见时处于列表的顶端。
特性
这个列表实现了许多其他实现所缺少的功能。包括:
1.快速滚动
2.页眉和页脚
3.可供点击的固定部分
除此之外它不会创建任何多余视图和布局,极其简洁。
用法
1、在layout.xml 文件中用com.hb.views.PinnedSectionListView代替标准ListView。
- <font size="3"><com.hb.views.PinnedSectionListView
- android:id="@android:id/list"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- /></font>
复制代码
2、扩展ListAdapter以实现PinnedSectionListAdapter接口。此时需要添加单独isItemViewTypePinned(int viewType)方法,该方法必须为所有固定视图类型返回true。
- <font size="3">// Our adapter class implements 'PinnedSectionListAdapter' interface
- class MyPinnedSectionListAdapter extends BaseAdapter
- implements PinnedSectionListAdapter {
-
- ...
-
- // We implement this method to return 'true' for all view types we want to pin
- @Override
- public boolean isItemViewTypePinned(int viewType) {
- return viewType == <type to be pinned>;
- }
- }</font>
复制代码