Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ankit1057/e247721fce1541018da4e974f2b5f2b3 to your computer and use it in GitHub Desktop.

Select an option

Save ankit1057/e247721fce1541018da4e974f2b5f2b3 to your computer and use it in GitHub Desktop.
Use this to iterate through a recycler view item and check each position to see if a view exists that has some specific text set
fun matchChildViewOfAccountTile(accountName: String, targetViewId: Int, itemMatcher: Matcher<View>): Matcher<View> =
object : BoundedMatcher<View, RecyclerView>(RecyclerView::class.java) {
override fun describeTo(description: Description) {
description.appendText("Has view id $targetViewId and matches $itemMatcher for item with name $accountName")
}
public override fun matchesSafely(recyclerView: RecyclerView): Boolean {
val itemCount = recyclerView.adapter.itemCount
for (i in 0 until itemCount) {
val holder = recyclerView.findViewHolderForAdapterPosition(i)
if (holder != null) {
val accountNameView = holder.itemView.findViewById<View>(R.id.accountTileAccountName) as TextView
if (accountNameView.text == accountName) {
val targetView = holder.itemView.findViewById<View>(targetViewId)
return itemMatcher.matches(targetView)
}
}
}
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment