android espresso:在适配器视图中未包含samerid的元素总数 [英] android espresso : total count of elements with samerid not in adapter view

查看:77
本文介绍了android espresso:在适配器视图中未包含samerid的元素总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除具有相同去除率的元素

I am trying to get the count of elements with same rid

此处的解决方案

The solutions here How to get count of items with same ids which are not in adapter view is not helping me.

 static int counter = 0;
public static Matcher<View> withIdAndDisplayed(final int id) {
    Checks.checkNotNull(id);
    return new TypeSafeMatcher<View>() {
        @Override
        public void describeTo(Description description) {
            description.appendText("with item id: " + id);
        }

        @Override
        public boolean matchesSafely(View view) {
            if ((view.getId() == id) && (view.getGlobalVisibleRect(new Rect())
                    && withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE).matches(view))){
                counter++;
                return true;
            }
            return false;
        }
    };
}

推荐答案

更新:

我看到您正在尝试获取不是adapterView的子视图计数. 请参阅 https://groups.google.com/论坛/#!topic/android-test-kit-discuss/avLaBnBWr70

I see you trying to get child view count which is not an adapterView. See this one https://groups.google.com/forum/#!topic/android-test-kit-discuss/avLaBnBWr70

原始答案:

您是否正在使用RecyclerView?

Are you using RecyclerView?

我在测试中使用以下代码来获取RecyclerView的大小.

I used below code in my tests to get the RecyclerView size.

 public static Matcher<View> withRecyclerViewSize(final int size) {
    return new TypeSafeMatcher<View>() {

        @Override
        public boolean matchesSafely(final View view) {
            final int actualListSize = ((RecyclerView) view).getAdapter().getItemCount();
            LOGD(TAG, "RecyclerView actual size " + actualListSize);
            return actualListSize == size;
        }

        @Override
        public void describeTo(final Description description) {
            description.appendText("RecyclerView should have " + size + " items");
        }
    };
}

用法:onView(withId(R.id.resource_id)).check(matches(withRecyclerViewSize(expectedSize)));

在这种情况下,resource_id是RecyclerView.

In this case resource_id is RecyclerView.

这里有几个示例: https://gist.github.com/chemouna/00b10369eb1d5b00401b.

这篇关于android espresso:在适配器视图中未包含samerid的元素总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆