Assigned ViewHolder ids to section views based on the section's hash code

This commit is contained in:
Tobias Erthal
2016-10-03 13:17:14 +02:00
parent da543345ee
commit 8a83b7c92a
2 changed files with 11 additions and 12 deletions

View File

@@ -115,6 +115,16 @@ public abstract class SectionCursorAdapter<C extends CursorAdapter.AbstractCurso
*/
protected abstract T getSectionFromCursor(C cursor) throws IllegalStateException;
/**
* Return the id of the item represented by the row the cursor
* is currently moved to.
* @param section The section item to get the id from
* @return The id of the dataset
*/
public long getIdFromSection(T section) {
return section != null ? section.hashCode() : 0L;
}
@Override
public int getItemCount() {
return super.getItemCount() + mSectionMap.size();
@@ -122,21 +132,13 @@ public abstract class SectionCursorAdapter<C extends CursorAdapter.AbstractCurso
@Override
public final long getItemId(int listPosition) {
/*
int index = mSectionMap.indexOfKey(listPosition);
if (index < 0) {
int cursorPosition = getCursorPositionWithoutSections(listPosition);
return super.getItemId(cursorPosition);
} else {
T section = mSectionMap.valueAt(index);
return section != null ? section.hashCode() : 0L;
} */
if (isSection(listPosition)) {
return RecyclerView.NO_ID;
} else {
int cursorPosition = getCursorPositionWithoutSections(listPosition);
return super.getItemId(cursorPosition);
return getIdFromSection(section);
}
}

View File

@@ -112,10 +112,7 @@ public class FastScrollRecyclerView extends RecyclerView implements RecyclerView
if (count > 0) {
stopScroll();
int pixelsToScroll = (int) (computeVerticalScrollRange() * fraction);
System.out.println("ScrollBy Fraction: " + fraction + ", Pixel: " + pixelsToScroll);
scrollBy(0, pixelsToScroll);
}
}