在我的项目中,我有扩展ArrayAdapter<String>
和实现的类SectionIndexer
。在实现方法时getPositionForSection
,getSectionForPosition
我发现了一些奇怪的行为。
为什么节索引器在getSectionForPosition
返回 0 时工作正常?
public int getSectionForPosition(int position) {
return 0;
}
许多教程中都使用了这个实现,例如:
http://androidopentutorials.com/android-listview-fastscroll/
http://www.survivingwithandroid.com/2012/12/android-listview-sectionindexer-fastscroll.html
文档说
给定适配器内的一个位置,返回相应部分在部分对象数组中的索引。
所以如果我的列表有 5 个以字母“A”开头的项目和一些以字母“B”开头的项目,那么 getSectionForPosition(5) 应该返回 1。