There is no way of making it infinite, but there is a way to make it look like infinite.
-
in your adapter override
getCount()
to return something big likeInteger.MAX_VALUE
:@Override public int getCount() { return Integer.MAX_VALUE; }
-
in
getItem()
andgetView()
modulo divide (%) position by real item number:@Override public Fragment getItem(int position) { int positionInList = position % fragmentList.size(); return fragmentList.get(positionInList); }
-
at the end, set current item to something in the middle (or else, it would be endless only in downward direction).
// scroll to middle item recyclerView.getLayoutManager().scrollToPosition(Integer.MAX_VALUE / 2);