cymcsg / UltimateRecyclerView

A RecyclerView(advanced and flexible version of ListView in Android) with refreshing,loading more,animation and many other features.
Apache License 2.0
7.22k stars 1.43k forks source link

Swipe layout not working inside viewpager. #84

Open Morteza-Rastgoo opened 9 years ago

Morteza-Rastgoo commented 9 years ago

I implemented swipe layout like the example and it worked perfectly, but when i moved the swipeRecyclerView inside a child fragment that is inside a ViewPager, swipe doesn't intercept touch event and instead, viewpager swipes the fragments... What can i do to fix this?

cymcsg commented 9 years ago

There is an attribute called swipeOffsetRight.Do you want this attribute? I read you refer this to other issue.

Morteza-Rastgoo commented 9 years ago

This is not what i'm talking about here! your answer is for my other issue!

cymcsg commented 9 years ago

Sorry for that.I misunderstanding your issue.You want to use recyclerview in Viewpager,don't you?

Rainer-Lang commented 9 years ago

I also.

Morteza-Rastgoo commented 9 years ago

Yes. I have a this hierarchy :

Fragment > ViewPager > ChildFragment > UltimateRecyclerView > SwipeItem

The problem is that the view pager intercepts the touch event and i can't swipe item(SwipeHold).

Rainer-Lang commented 9 years ago

@mori-honest Is the viewpager swipeable?

Morteza-Rastgoo commented 9 years ago

Yes, view pager is swipeable.

Rainer-Lang commented 9 years ago

I have a solution. Will post in an hour

Rainer-Lang commented 9 years ago

I have read many blogs and sites with tipps.... I only found one acceptable solution for me.

You have to make your own ViewPager class:

public class OwnViewPager extends ViewPager {

    private boolean enabled;

    public OwnViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.enabled = true;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return this.enabled && super.onTouchEvent(event);

    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        return this.enabled && super.onInterceptTouchEvent(event);

    }

    public void setPagingEnabled(boolean enabled) {
        this.enabled = enabled;
    }
}

Use setPagingEnabled(boolean) to en/disable swipe for the ViewPager. Also a solution is to make this accessable via xml.