getPositionForSection与getSectionForPosition的用法(Listview分块显示)
来源:互联网 发布:建信养老飞月宝 知乎 编辑:程序博客网 时间:2024/03/28 18:09
在Listview的分块显示中,常常在自定义的adapter中会用到getPositionForSection
和getSectionForPosition
这两个方法,这两个方法的目的在于使Listview中的每个item布局中的显示section块的TextView显示还是隐藏,比如在联系人主界面中的相同姓氏只显示每块的第一个item中的TextView,其余的都隐藏,这就是Listview的分块显示的原理,或者说其实现方式之一吧。
假设keyEt就是该TextView,该段代码写在自定义adapter的public View getView(int position, View convertView, ViewGroup parent) 方法中:
int section=getSectionForPosition(position);int pos=getPositionForSection(section);if(pos==position){keyEt.setVisibility(View.VISIBLE);}else{keyEt.setVisibility(View.GONE);}这两个方法的原理如下:
1、
getPositionForSection返回每个section的第一个元素位置,如
Position Data getSectionForPosition(position)_________ __________ ______________________________0 Abhfdf 01 Achahtkh 02 Ahtjlarej 03 Bchatkd 14 Bjklhdsfoi 15 Bzhafdlsfk 16 Cj fadsfkj 2
getPositionForSection(1)
returns 3getPositionForSection(2)
returns 62、
getSectionForPosition返回该position处的section的位置
1 0
- getPositionForSection与getSectionForPosition的用法(Listview分块显示)
- getSectionForPosition()与getPositionForSection()
- getPositionForSection与getSectionForPosition
- SectionIndexer中的getSectionForPosition()与getPositionForSection()解惑
- SectionIndexer中的getSectionForPosition()与getPositionForSection()解惑
- SectionIndexer中的getSectionForPosition()与getPositionForSection()解惑
- SectionIndexer中的getSectionForPosition()与getPositionForSection()解惑
- SectionIndexer中的getSectionForPosition()与getPositionForSection()解惑
- SectionIndexer中的getSectionForPosition()与getPositionForSection()解惑
- SectionIndexer接口中的getPositionForSection与getSectionForPosition
- listview分块显示
- ListView显示自定义(listview与adapter用法)
- 分块(一) 分块的思想与基础功能实现
- listView与adapter的用法
- ListView与GridView的用法
- adapter.getPositionForSelection()和getSectionForPosition()的区别
- Android ListView与Button的显示
- ListView控制Fragment的显示与隐藏
- Caffe Windows版本的编译
- 表达式
- Swift之switch使用
- 5.x控件:FloatingActionButton、SnackBar、DrawerLayout、NavigationView
- ab post 测试 http 和 webservice 接口方法及用例
- getPositionForSection与getSectionForPosition的用法(Listview分块显示)
- 中小型网站架构分析及优化
- IOS的app发布时遇到的问题
- JQuery、AJAX加载数据时候的loading加载动画实现步骤
- UIPageControl基本用法
- python里爬取页面中图片命令
- adb logcat 命令详解 log过滤
- Android开发 深入理解AsyncTask
- IOS动画ViewAnimations