TUBB/SwipeMenu

setOnClickListener in an element inside the main view

jeffersonlicet opened this issue · 9 comments

How to bind setOnClickListener i receive java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.tubb.smrv.swiper.Swiper.isClickOnContentView(android.view.View, float)'

TUBB commented

You may have forgotten to set a menu view.

it happened to me too. if all view in menu view is invisible.

Hello guys, i've faced the same problem. so here is what i've done to solve it:

public class SwipeMenuLayout extends SwipeHorizontalMenuLayout {

    //constructors

    @Override
    public void smoothOpenMenu(int duration) {
        if (mCurrentSwiper != null) {
            super.smoothOpenMenu(duration);
        }
    }

    @Override
    public void smoothCloseMenu(int duration) {
        if (mCurrentSwiper != null) {
            super.smoothCloseMenu(duration);
        }
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_UP:
                return mCurrentSwiper != null && super.onInterceptTouchEvent(ev);
            default:
                return super.onInterceptTouchEvent(ev);
        }
    }
}

It's a simple subclass of SwipeHorizontalMenuLayout (i suppose it will work with vertical implementation as well) with fix for main problem - null mCurrentSwiper.

Hope it'll help someone :)

TUBB commented

fixed -> 5.4.3

in 5.4.5 still not fixed. on ACTION_UP mCurrentSwiper is null but isMenuOpen() returns true. And this cause crash

TUBB commented

Please provide the exception stacktrace
Thanks

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.tubb.smrv.swiper.Swiper.isClickOnContentView(android.view.View, float)' on a null object reference at com.tubb.smrv.SwipeHorizontalMenuLayout.onInterceptTouchEvent(SwipeHorizontalMenuLayout.java:54) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2108) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at com.tubb.smrv.SwipeMenuRecyclerView.dispatchTouchEvent(SwipeMenuRecyclerView.java:34) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at com.android.internal.policy.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2403) at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1737) at android.app.Activity.dispatchTouchEvent(Activity.java:2765) at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:68) at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:68) at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2364) at android.view.View.dispatchPointerEvent(View.java:9514) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4230) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4096) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3787) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3844) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3661) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3669) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5922) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5896) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5857) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6025)

another issue that i noticed. after fast scrolling, holder don't receive onClick event during some short time. during that time all clicks are ignored.

TUBB commented

Sorry, i can't reappear the bug again.
I just write the code like this.

if (mCurrentSwiper != null) {
    isClickOnContentView = mCurrentSwiper.isClickOnContentView(this, mv);
}

Please check the version 5.4.6.
Thanks.