use of android.widget.SectionIndexer in project ABPlayer by winkstu.
the class XStickyListHeadersView method wrapAdapter.
private AdapterWrapper wrapAdapter(ListAdapter adapter) {
AdapterWrapper wrapper;
if (adapter instanceof SectionIndexer) {
wrapper = new SectionIndexerAdapterWrapper(getContext(), (StickyListHeadersAdapter) adapter);
} else {
wrapper = new AdapterWrapper(getContext(), (StickyListHeadersAdapter) adapter);
}
wrapper.setDivider(mDivider);
wrapper.setDividerHeight(mDividerHeight);
wrapper.registerDataSetObserver(mDataSetChangedObserver);
wrapper.setOnHeaderClickListener(mAdapterHeaderClickListener);
return wrapper;
}
use of android.widget.SectionIndexer in project bdcodehelper by boredream.
the class PinnedSectionListView method findCurrentSectionPosition.
int findCurrentSectionPosition(int fromPosition) {
ListAdapter adapter = getAdapter();
// dataset has changed, no candidate
if (fromPosition >= adapter.getCount())
return -1;
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;
}
// no candidate found
return -1;
}
Aggregations