2

A ViewPager contains a RecyclerView. I am attempting to swipe an item in that RecyclerView, but unfortunately at times,the ViewPager gets swiped. Is this a bug in Espresso? The following code has been used to achieve this.

onView(withId(R.id.recyclerview)).perform(
                RecyclerViewActions.actionOnItemAtPosition(1, swipeLeft()));

Looking out for a clear distinction between swiping the list item and the ViewPager

JGPhilip
  • 1,388
  • 17
  • 19

1 Answers1

0

I think it is possible to prevent viewpager intercept touch event in recyclerview, like this:

mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
    @Override
    public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent e) {
        int action = e.getAction();
        switch (action) {
            case MotionEvent.ACTION_POINTER_UP:
                recyclerView.getParent().requestDisallowInterceptTouchEvent(true);
                break;
        }
        return false;
    }
}
hakim
  • 3,819
  • 3
  • 21
  • 25