Having gridView which has some images. The gridView\'s cell comes out from same predefined layout, which has same id and desc.
R.id.item_image == 2131
Tried @FrostRocket answer as was looking most promissing but needed to add some customisations:
public static Matcher withIndex(final Matcher matcher, final int index) {
return new TypeSafeMatcher() {
int currentIndex;
int viewObjHash;
@SuppressLint("DefaultLocale") @Override
public void describeTo(Description description) {
description.appendText(String.format("with index: %d ", index));
matcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
if (matcher.matches(view) && currentIndex++ == index) {
viewObjHash = view.hashCode();
}
return view.hashCode() == viewObjHash;
}
};
}