Example usage for android.widget SectionIndexer getPositionForSection

List of usage examples for android.widget SectionIndexer getPositionForSection

Introduction

In this page you can find the example usage for android.widget SectionIndexer getPositionForSection.

Prototype

int getPositionForSection(int sectionIndex);

Source Link

Document

Given the index of a section within the array of section objects, returns the starting position of that section within the adapter.

Usage

From source file:com.dm.xz.views.PinnedSectionListView.java

int findCurrentSectionPosition(int fromPosition) {
    ListAdapter adapter = getAdapter();/*from w  ww  . j  a  v  a 2 s .c  o m*/

    if (fromPosition >= adapter.getCount())
        return -1; // dataset has changed, no candidate

    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
}

From source file:com.yahala.ui.Views.PinnedSectionListView.java

int findCurrentSectionPosition(int fromPosition) {
    ListAdapter adapter = getAdapter();/*  w  ww. j  a  va2s. com*/

    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
}