0

I have a scenario where i have to enable swiping from fragment of viewpager and when all swiping being done from fragment then i have to allow viewpager swiping to move to next fragment. I am not able to figure this out.

For eg i have 4 text view in a fragment then first textview should come on first swipe right and if user swipe again to the right then next textview should appear and so on untill all 4 textview should loaded in fragment then viewpager swiping should be enable.

I have used setOnTouchListener on layout of my fragment inside viewpager but its now working.

setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction())

                {
                    case MotionEvent.ACTION_DOWN: {
                        oldTouchValue = event.getX();
                        break;
                    }
                    case MotionEvent.ACTION_UP: {
                        float currentX = event.getX();
                        if (oldTouchValue < currentX) {
                            // swiped left


                        }
                        if (oldTouchValue > currentX) {

                            // swiped right
                        }
                        break;
                    }
                }
                System.out.println("TOuch ");
                return false;
            }
        });

Please help me to resolve this issue.

  • 1
    I would try disabling swipes for this specific situation and enabling them afterwards. On how to disable swipes see this SO question: http://stackoverflow.com/questions/9650265/how-do-disable-paging-by-swiping-with-finger-in-viewpager-but-still-be-able-to-s – mhenryk Oct 24 '16 at 12:34
  • Thanks mhenry. onInterceptTouchEvent can disable or enable the swiping of viewpager. but can i use viewpager instance from fragment to control swiping ? – feroz siddiqui Oct 24 '16 at 12:40

0 Answers0