gpt4 book ai didi

android-espresso - 如何获取不在适配器 View 中的具有相同 ID 的项目数

转载 作者:行者123 更新时间:2023-12-01 06:52:04 24 4
gpt4 key购买 nike

我有一个项目的多个实例存在的情况,我想计算它们。
我的 View 匹配器如下:

 public static ViewInteraction onTestPanelView(){
return onView(allOf(withId(R.id.myId), isDisplayed()));
}

使用 View 匹配器,我收到以下错误:

com.google.android.apps.common.testing.ui.espresso.AmbiguousViewMatcherException: '(with id: is <2131427517> and is displayed on the screen to the user)' matches multiple views in the hierarchy. Problem views are marked with '****MATCHES****' below.



这是正确的,因为我有多个具有相同 ID (R.id.myId) 的项目实例。我想编写一个方法来返回符合我的条件的 View 计数。请注意 - 它们不在适配器 View 中。

最佳答案

老问题,但可能有人会发现它很有用。

来自 here你会发现:

In the vast majority of cases, the onView method takes a hamcrest matcher that is expected to match one — and only one — view within the current view hierarchy. Matchers are powerful and will be familiar to those who have used them with Mockito or Junit. If you are not familiar with hamcrest matchers, we suggest you start with a quick look at this presentation.



您可以在下面找到一个解释,其中包含一个仅查找一个 View 的示例。我已经调整了我的测试来做到这一点。但是,可能有一种解决方法,例如查找父容器并计算其上某个实例的 View 。

suggestion没有帮助我。

关于android-espresso - 如何获取不在适配器 View 中的具有相同 ID 的项目数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27430500/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com