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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations