Java 如何使用浓缩咖啡获取列表中文本视图的计数?

Java 如何使用浓缩咖啡获取列表中文本视图的计数?,java,android,automation,android-espresso,Java,Android,Automation,Android Espresso,我有一个列表,其中textView@+id/job_状态在页面中出现的次数。我需要找到它的计数并断言它 情景: Filter(5) <Item1> <Item2> <Item3> 它告诉我一个错误:android.R.id.list匹配层次结构中的多个视图。此id已在应用程序的多个位置使用。这个问题还有别的解决办法吗 public static class RecyclerViewAssertion implements ViewAssertion { pr

我有一个列表,其中textView@+id/job_状态在页面中出现的次数。我需要找到它的计数并断言它

情景:

Filter(5)
<Item1>
<Item2>
<Item3>
它告诉我一个错误:android.R.id.list匹配层次结构中的多个视图。此id已在应用程序的多个位置使用。这个问题还有别的解决办法吗

public static class RecyclerViewAssertion implements ViewAssertion {
private final int expectedCount;

public RecyclerViewAssertion(int expectedCount) {
    this.expectedCount = expectedCount;
}

@Override
public void check(View view, NoMatchingViewException 
noViewFoundException) {
if (noViewFoundException != null) {
    throw noViewFoundException;
}
RecyclerView recyclerView = (RecyclerView) view;
RecyclerView.Adapter adapter = recyclerView.getAdapter();
assertThat(adapter.getItemCount(), is(expectedCount));
}
}

onView (withId(android.R.id.list)).check(new 
JobsPage.RecyclerViewAssertion(5));