Created
June 6, 2018 14:01
-
-
Save dominicthomas/1a0d6d7c81eb69e5ad56a62cb7bfd11d 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
it's really perfect