【发布时间】:2015-01-19 07:33:46
【问题描述】:
我有带有图片和文字的ListView。当我尝试单击项目时,出现错误
android.support.test.espresso.AmbiguousViewMatcherException: 'with id: com.cifrasoft.telefm:id/cardsGridView' matches multiple views in the hierarchy.
Problem views are marked with '****MATCHES****' below.
我使用以下代码:
onData(hasToString(startsWith("Item Text")))
.inAdapterView(withId(R.id.cardsGridView))
.perform(click());
我可以使用Adapter的位置点击ListView,没有匹配或startWith吗?
【问题讨论】:
-
这意味着您在视图层次结构中有多个具有命名 ID 的视图。您可以发布整个错误消息吗?
-
是的,当然。但是完整的错误太长了。pastebin.com/eahDGDMb
-
从整个层次结构来看,您似乎有一个 ViewPager,它显示了多个页面,其中三个具有带有 ID cardsGridView 的 AdapterView。因此,您有一个 AdapterView,即 ViewPager,以及另一个嵌套的 AdapterView,即您的 ListView。可行的方法是给从 Adapter.getView 返回的视图单独的 ID 或标签,并在 inAdapterView() 调用中使用 isDescendantOf() 匹配器和 withId。
-
haffax,你能给出代码的例子吗?没找到?
标签: android android-listview android-espresso ui-testing