Android 计算framelayout中的文本视图数

Android 计算framelayout中的文本视图数,android,android-espresso,Android,Android Espresso,我不熟悉espresso UI测试,并尝试计算应用程序中特定屏幕上显示的文本视图数。我试过下面的方法 onView(allOf(withId(R.id.listview), isDescendantOfA(withId(R.id.framelayout)) .check(ViewAssertions.matches (Matchers.withListSize (2))))) 使用以下自定义匹配器 class Matchers { public static

我不熟悉espresso UI测试,并尝试计算应用程序中特定屏幕上显示的文本视图数。我试过下面的方法

onView(allOf(withId(R.id.listview),
    isDescendantOfA(withId(R.id.framelayout))
            .check(ViewAssertions.matches (Matchers.withListSize (2)))))
使用以下自定义匹配器

class Matchers {
  public static Matcher<View> withListSize (final int size) {
    return new TypeSafeMatcher<View> () {
      @Override public boolean matchesSafely (final View view) {
        return ((ListView) view).getCount () == size;
      }

      @Override public void describeTo (final Description description) {
        description.appendText ("ListView should have " + size + " items");
      }
    };
  }
}
类匹配器{
具有ListSize(最终整型大小)的公共静态匹配器{
返回新的TypeSafeMatcher(){
@覆盖公共布尔匹配安全(最终视图){
return((ListView)视图).getCount()==size;
}
@覆盖公共无效描述(最终描述){
description.appendText(“ListView应具有“+大小+”项”);
}
};
}
}
我试过这里提到的那个,不适用于最新版本