1

I'm in a class extending a FragmentActivity. To disable the viewpager swipe i wan't to override the onInterceptTouchEvent method which is not possible because i can't extend the viewpager class because i'm already extending the FragmentActivity class.

A solution for this problem would be to create a custom viewpager:

public class CustomViewPager extends ViewPager
{
    private boolean enabled;
    public CustomViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
            return this.enabled && super.onInterceptTouchEvent(event);
    }
}

and

 CustomViewPager viewPager;
 viewPager = findViewById(R.id.viewpager);

but then i get the following casting error:

android.support.v4.view.ViewPager cannot be cast to MainPage$CustomViewPager

are there some other ways to override the onInterceptTouchEvent method or to disable the view pager swipe?

  • Which casting error? Any helpful errors or logcat would be great to add in here. Thank you. Also: https://stackoverflow.com/questions/9650265/how-do-disable-paging-by-swiping-with-finger-in-viewpager-but-still-be-able-to-s – ʍѳђઽ૯ท Sep 10 '18 at 16:16

1 Answers1

1

Just write;

viewPager = (CustomViewPager) findViewById(R.id.viewpager);

The findViewById method returns view, you have to say which class will be initialized.

C. Soylu
  • 44
  • 3