Reputation: 12559
Let's say I have dynamic number of items coming from server. I can only show 4 items at most in one page. Other pages whould be accesible with swipe Please have a look at the image below. What is the best way to achieve this?
Upvotes: 0
Views: 105
Reputation: 1434
This could be achieved using
Approach
For example: if number of item recieved is 17 the number of pages will be 17/4+ 1(only if 17%4>0)
For example if page index in view pager 4
Make sure to keep the check ( index+4<=size of list of item) if (index+4>size of list of item) then the the item to be displayed will start from index and will go on till the size of list. if(index+4<=size of list)the item to be displayed will start from index i.e 4 in this case till next four element in list of items provided to the fragment.
In this way you can always get the required item out of the complete list
Upvotes: 1