/** @param position relative position in the indexed partition */ public int getSectionForPosition(int position) { if (mIndexer == null) { return -1; } return mIndexer.getSectionForPosition(position); }
int findCurrentSectionPosition(int fromPosition) { ListAdapter adapter = getAdapter(); if (adapter instanceof SectionIndexer) { // try fast way by asking section indexer SectionIndexer indexer = (SectionIndexer) adapter; int sectionPosition = indexer.getSectionForPosition(fromPosition); int itemPosition = indexer.getPositionForSection(sectionPosition); int typeView = adapter.getItemViewType(itemPosition); if (isItemViewTypePinned(adapter, typeView)) { return itemPosition; } // else, no luck } // try slow way by looking through to the next section item above for (int position = fromPosition; position >= 0; position--) { int viewType = adapter.getItemViewType(position); if (isItemViewTypePinned(adapter, viewType)) return position; } return -1; // no candidate found }