A recent project, the customer asked to slide to the last page after the Viewpager implementation of the main page, continue to swipe to return to the first page, that is, to achieve infinite loop scrolling, the effect is as follows:
Look at the next Viewpager does not slip to the end of the callback method, so think of the solution is, after the original last page and then add a first page, which is originally numbered a1,b,c three pages, now in the last side plus a page, into A1, B, C, A2 four pages, Then use the Onpageselected method in Onpagechangelistener to listen to the page switch, when the discovery is from the third page (c) switch to the fourth page (A1), call Viewpager setcurrentitem (0, False) method to jump back to the first page (A2), the following is the core code:
Viewpager.setonpagechangelistener (New Onpagechangelistener () {@Overridepublic void onpageselected (int arg0) {if (arg0 ==fragments.size ()-1) {Viewpaper.setcurrentitem (0, False);}} <span style= "White-space:pre" ></SPAN>}
* Where the Fragments array stores A1, B, C, A2 four pages
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Android" Viewpager for Infinite loop scrolling