Search in sources :

Example 6 with SectionIndexer

use of android.widget.SectionIndexer in project PullToRefresh-PinnedSection-ListView by tongcpp.

the class PinnedSectionListView method findCurrentSectionPosition.

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;
    }
    // no candidate found
    return -1;
}
Also used : SectionIndexer(android.widget.SectionIndexer) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) ListAdapter(android.widget.ListAdapter)

Example 7 with SectionIndexer

use of android.widget.SectionIndexer in project pinned-section-listview by beworker.

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;
}
Also used : SectionIndexer(android.widget.SectionIndexer) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) ListAdapter(android.widget.ListAdapter)

Example 8 with SectionIndexer

use of android.widget.SectionIndexer in project Ushahidi_Android by ushahidi.

the class MergeAdapter method getSectionForPosition.

@Override
public int getSectionForPosition(int position) {
    int section = 0;
    for (ListAdapter piece : pieces) {
        int size = piece.getCount();
        if (position < size) {
            if (piece instanceof SectionIndexer) {
                return (section + ((SectionIndexer) piece).getSectionForPosition(position));
            }
            return (0);
        } else {
            if (piece instanceof SectionIndexer) {
                Object[] sections = ((SectionIndexer) piece).getSections();
                if (sections != null) {
                    section += sections.length;
                }
            }
        }
        position -= size;
    }
    return (0);
}
Also used : SectionIndexer(android.widget.SectionIndexer) ListAdapter(android.widget.ListAdapter)

Example 9 with SectionIndexer

use of android.widget.SectionIndexer in project Ushahidi_Android by ushahidi.

the class MergeAdapter method getPositionForSection.

@Override
public int getPositionForSection(int section) {
    int position = 0;
    for (ListAdapter piece : pieces) {
        if (piece instanceof SectionIndexer) {
            Object[] sections = ((SectionIndexer) piece).getSections();
            int numSections = 0;
            if (sections != null) {
                numSections = sections.length;
            }
            if (section < numSections) {
                return (position + ((SectionIndexer) piece).getPositionForSection(section));
            } else if (sections != null) {
                section -= numSections;
            }
        }
        position += piece.getCount();
    }
    return (0);
}
Also used : SectionIndexer(android.widget.SectionIndexer) ListAdapter(android.widget.ListAdapter)

Example 10 with SectionIndexer

use of android.widget.SectionIndexer in project Ushahidi_Android by ushahidi.

the class BaseSectionListAdapter method getSectionForPosition.

@Override
public int getSectionForPosition(int position) {
    int section = 0;
    for (ListAdapter piece : pieces) {
        int size = piece.getCount();
        if (position < size) {
            if (piece instanceof SectionIndexer) {
                return (section + ((SectionIndexer) piece).getSectionForPosition(position));
            }
            return (0);
        } else {
            if (piece instanceof SectionIndexer) {
                Object[] sections = ((SectionIndexer) piece).getSections();
                if (sections != null) {
                    section += sections.length;
                }
            }
        }
        position -= size;
    }
    return (0);
}
Also used : SectionIndexer(android.widget.SectionIndexer) ListAdapter(android.widget.ListAdapter)

Aggregations

SectionIndexer (android.widget.SectionIndexer)17 ListAdapter (android.widget.ListAdapter)10 HeaderViewListAdapter (android.widget.HeaderViewListAdapter)7 Paint (android.graphics.Paint)3 Adapter (android.widget.Adapter)2 BaseAdapter (android.widget.BaseAdapter)2 ExpandableListAdapter (android.widget.ExpandableListAdapter)1 WrapperListAdapter (android.widget.WrapperListAdapter)1 AdapterWrapper (com.emilsjolander.components.stickylistheaders.AdapterWrapper)1 SectionIndexerAdapterWrapper (com.emilsjolander.components.stickylistheaders.SectionIndexerAdapterWrapper)1 StickyListHeadersAdapter (com.emilsjolander.components.stickylistheaders.StickyListHeadersAdapter)1