The way I have seen this done is to define the number of items that you have to display as Integer.MAX_VALUE
. In onBindViewHolder()
of the adapter you will have something like:
@Override
public int getItemCount() {
return (mItems == null) ? 0 : Integer.MAX_VALUE;
}
Now you can't really have Integer.MAX_VALUE
items to display, so this is a small lie to the RecyclerView
. In your code, map the index value from 0...Integer.MAX_VALUE-1 to 0...your_item_count-1 like this in onBindViewHolder()
:
int realPos = position % mItems.size();
Use realPos
instead of the position that the RecyclerView
passes in.
All that is left is to scroll the RecyclerView
to the middle of the range:
mRecycler.scrollToPosition(Integer.MAX_VALUE / 2);
This works OK, but is it perfect? No, but close enough; I don't think anyone will scroll enough to see the flaw. (It will stop wrapping at the extremes.)