0

I am trying to use damajia's AndroidImageSlider and for my app I need to disable the swipe feature. From this link, they say that the have included in setSwipeEnabled function. But when I tried to call

sliderLayout.setSwipeEnabled()

This function doesn't exist. So, where to call this function?

My gradle file is :

implementation 'com.daimajia.slider:library:1.1.5@aar' 
the newbie coder
  • 652
  • 2
  • 8
  • 27

3 Answers3

3

You can override touch listener and not call their super whenever you want to stop swipe otherwise call it.

Sameer Jani
  • 1,192
  • 9
  • 16
1

You need to make subclass of SliderLayout and override OnInterceptTouchEvent that returns true. Use that class instead of SliderLayout in your code.

public class SlideLayout extends SliderLayout {


    public SlideLayout(Context context) {
        super(context);
    }

    public SlideLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SlideLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return true;
    }
}
Robert Longson
  • 118,664
  • 26
  • 252
  • 242
0

create a boolean variable and setter in SliderLayout.java

private boolean isDisableTouchEvent = true;
public void setDisableTouchEvent(boolean disableTouchEvent) {
    isDisableTouchEvent = disableTouchEvent;
}

and replace onInterceptTouchEvent function with below

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (isDisableTouchEvent)
        return true;
    else {
        int action = ev.getAction();
        switch (action) {
            case MotionEvent.ACTION_DOWN:
                pauseAutoCycle();
                break;
        }
        return false;
    }
}

after that you can disable swipe with this

slider.setDisableTouchEvent(true);