Java Code Examples for android.widget.SectionIndexer#getSectionForPosition()

The following examples show how to use android.widget.SectionIndexer#getSectionForPosition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PinnedSectionListView.java    From AndroidWeekly with Apache License 2.0 6 votes vote down vote up
int findCurrentSectionPosition(int fromPosition) {
    ListAdapter adapter = getAdapter();

    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
}
 
Example 2
Source File: PinnedSectionListView.java    From Yahala-Messenger with MIT License 6 votes vote down vote up
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
}
 
Example 3
Source File: PinnedSectionListView.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
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
}
 
Example 4
Source File: PinnedSectionListView.java    From Contacts with MIT License 6 votes vote down vote up
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
}
 
Example 5
Source File: PinnedSectionListView.java    From PullToRefresh-PinnedSection-ListView with MIT License 6 votes vote down vote up
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
}
 
Example 6
Source File: PinnedSectionListView.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
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
}
 
Example 7
Source File: PinnedSectionListView.java    From Kernel-Tuner with GNU General Public License v3.0 6 votes vote down vote up
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
}
 
Example 8
Source File: PinnedSectionListView.java    From KUAS-AP-Material with MIT License 5 votes vote down vote up
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;
}
 
Example 9
Source File: PinnedSectionListView.java    From KUAS-AP-Material with MIT License 5 votes vote down vote up
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;
}