2

I have viewPager with adapter that override onPageSelected , and i want to prevent the view pager from being selected at last page but swipe-able so when the user leave the finger it will return to previous page .

what is the best way to achive that ?

Thanks in advance !

  • 1
    How about the obvious? When last page is selected, select previous page. – Marius Aug 18 '14 at 14:07
  • based on your answer, i used callback when last page is selected to call view pager set Current Item with smooth Scroll CurrentItem(index,true) and its look very good , thanks ! – Eliyahu Shwartz Aug 18 '14 at 14:23
  • 1
    Please post your solved solution as an answer and accept it rather than editing the original question – biddulph.r Aug 18 '14 at 14:30
  • I wanted to do the same for page 2 out of 4 pages. The application re-displays the page it was originally, as I wanted, but the underline of the name of the tab does not go with it, and stays under the name of the tab I do not want to be selected. How can I cause the underline to move too? – Zvi Mar 04 '16 at 11:10

1 Answers1

1

based on Marius answer, i used callback when last page is selected to call view pager set Current Item with smooth Scroll.

// VIEW PAGER ADAPTER
public void onPageSelected(int index) {

if(index == size)
communicator.refreshViewPager();

//MAIN ACTIVITY

@Override
public void refreshViewPager() {
pager.setCurrentItem(size -1, true);
DManager.getInstance().scan(1500);

}

  • Can you please show the full code of defining the callback. As far as I know the `onPageSelected` is part of the view pager and not part of the adapter. – Zvi Apr 12 '16 at 02:45