From java:
onView(withId(R.id.recyclerView)).perform(RecyclerViewActions.scrollTo(
hasDescendant(withText(artistResult.getNameVariations().get(0)))));
Trying to convert to Kotlin:
onView(withId(R.id.recyclerView)).perform(RecyclerViewActions.scrollTo(
hasDescendant(withText(artistResult.nameVariations[0]))))
I get this stacktrace:
Error:(63, 71) Type inference failed: Not enough information to infer parameter VH in fun <VH : RecyclerView.ViewHolder!> scrollTo(itemViewMatcher: Matcher<View!>!): RecyclerViewActions.PositionableRecyclerViewAction!
Please specify it explicitly.
I'm not entirely sure where I can specify "it" explicitly. When this has come up previously it's because I didn't initialise the value correctly, but here I'm calling a method. Any ideas?
I needed to add <RecyclerView.ViewHolder>
to scrollTo
onView(withId(R.id.recyclerView)).perform(
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
hasDescendant(withText(artistResult.nameVariations[0]))))
One can get easily confused about which VH among many(specially if multiple VHs in a single RecyclerView) to use, you can simply use Generic ViewHolder i.e RecyclerView.ViewHolder
like :
RecyclerViewActions.actionOnItem<RecyclerView.ViewHolder>
RecyclerViewActions.actionOnHolderItem<RecyclerView.ViewHolder>
RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>
etc.
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With