Reputation: 195
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.
Upvotes: 7
Views: 9943
Reputation: 1292
Tell it about the ViewHolder.
onView(withId(R.id.recyclerview)).perform(
RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(
YOUR_POSITION
)
)
Upvotes: 2
Reputation: 6910
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.
Upvotes: 13