How to skip a page in a ViewPager depending on certain condition , swiping forward or backward , knowing that i don't know the the position of these pages .
Asked
Active
Viewed 2,137 times
4
-
I've rolled back your edit as it is not appropriate to include answers in questions. – IKavanagh Oct 22 '15 at 08:13
-
i know but i didnt know where to add it , shall i delete the question ? – Ali Reda Oct 22 '15 at 08:37
1 Answers
1
Yes you can. Normally what happens is that you will create a ViewPager
and set an adapter to it. This adapter has the getItem(position)
method. You override this method and for each position you will spit out a Fragment
. This is the place where you need to check your condition and send out different Fragment
.
However if you are going to reduce the number of items, you also need to adapt the getCount()
to suit your needs.
More info here:
-
thanks for your reply, i know i can add a condition to the adapter , my question was if there is a way to skip the page so i dont have to test if iam scrolling forward or backward. – Ali Reda Oct 21 '15 at 07:55
-
When you say skip, do you mean like when you swipe , it should be 1.. 2.. 5.. 6.. rather than 1.. 2.. 3.. 4.. 5.. 6.. ? – Henry Oct 21 '15 at 08:08
-
no it should be 1..2..3..5..6.. the problem is that i don't know the number or position of the pages that i want to skip , although they never are consecutive , and i don't know the size of my view pager too , they all depend on the web service response . – Ali Reda Oct 21 '15 at 08:18
-
So are you saying that you are going to construct the ViewPager based on the webservice response, or even after the creating of the ViewPager, you want to update the pager with the new webservice response? In any case, you have to handle this by handling the getCount() and getItem(). The first scenario is simple, since the ViewPager is static. – Henry Oct 21 '15 at 08:21
-