How to iterate over elements in Android RecyclerView?

How can you iterate over elements in Android RecyclerView?

I would like to have a RecyclerView that scrolls horizontally. When the end is reached to the right, it just continues scrolling, restarting the list of items. same left.


For example:
List of items: 0,1,2,3,4,5,6,7,8,9
Initial view shows: 0,1,2,3,4,5,6,7
After scrolling 5 points to the right: 5 , 6,7,8,9,0,1,2
After scrolling 2 positions to the left: 8,9,0,1,2,3,4,5

+4
source share
2 answers

: getItemCount() return Integer.MAX_VALUE, , , itemsList.get(position % list.size)
, , 0 .

, , scrollToPosition(int x) LayoutManager, x % yourList.size() == 0 x - Integer.MAX_VALUE / 2 (~ 1 )

, 0 getItemCount, 0. .

return list.size == 0 ? 0 : Integer.MAX_VALUE
+5


= 3x

original list: 0,1,2,3,4,5,6,7,8,9
new list     : 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9

RecyclerView, RecyclerView 10 (10 - ). , 10 , .

, , RecyclerView , RecyclerView. . ,

-1

Source: https://habr.com/ru/post/1649007/


All Articles