7

I have a heterogeneous recycler view and I am trying to scroll it to item at position 30. My test is passing but I cannot see the screen actually scrolling.

onView(withId(R.id.content_view))
    .perform(RecyclerViewActions.scrollToPosition(30));

This is what I am doing to scroll.

Pang
  • 9,564
  • 146
  • 81
  • 122
OkDroid
  • 185
  • 3
  • 11

3 Answers3

13

Use scrollToHolder():

onView(withId(R.id.recyclerViewId))
    .perform(scrollToHolder(viewHolderMatcher(some_parameter_to_match)));

where viewHolderMatcher(some_parameter_to_match) returns Matcher<RecyclerView.ViewHolder> i.e. the position of the holder/item in the RecyclerView.

Or only by position:

onView(withId(rvLayoutId))
    .perform(actionOnItemAtPosition(256, scrollTo()));

last one is from here.

denys
  • 6,834
  • 3
  • 37
  • 36
2

Have you tried the ViewActions swipeDown?

Victor Hugo Montes
  • 1,270
  • 1
  • 17
  • 28
2

Tell it about the ViewHolder.

onView(withId(R.id.recyclerview)).perform(
        RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(
          YOUR_POSITION
        )
      )
Akshay Nandwana
  • 1,260
  • 11
  • 18