2

I am trying to implement View Pager and succeed in it.
Currently I am using a Listener to load some contents from DB when a page is selected But I don't know How to make a toast when users try to scroll beyond the first and the last items in the ViewPager.
This is my Listner

.setOnPageChangeListener(new OnPageChangeListener() {    


            @Override
            public void onPageSelected(int arg0) {

                getMonthdays(arg0);
                Global.setSelectedMonth(""+(currentpos+1));

            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {

            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
                System.out.println(" onPageScrollStateChanged : "+arg0);

            }
        });

I think onPageScrollStateChanged can be used But i dont know how to do it...
Please Help me, Any Ideas and Suggestions are welcome

Renjith K N
  • 2,613
  • 2
  • 31
  • 53

1 Answers1

0

Check index of item in the following method

    @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {

        }

then if the index is last then show the Toast. Easy :)

For detecting the Gesture of the user override this method and do some maths.

    @Override
public boolean onTouchEvent(MotionEvent event) {
    // TODO Auto-generated method stub
    return super.onTouchEvent(event);
}

or you can refer the code here

Community
  • 1
  • 1
Ali Imran
  • 8,927
  • 3
  • 39
  • 50
  • But i think there is a problem if the user tries to scroll backwards from the last item How to detect that and the same case for the first one tooo. – Renjith K N Nov 29 '12 at 14:36