Android 浓缩咖啡罐';在自定义视图类中找不到视图
我有一个自定义的Android 浓缩咖啡罐';在自定义视图类中找不到视图,android,android-espresso,Android,Android Espresso,我有一个自定义的视图类公共类Foo扩展了RelativeLayout{…},其中有一个EditText。Foo类有一个膨胀的XML布局,其EditText也有一个id,但它无法找到EditText 我用的是浓缩咖啡代码: onView(allOf(withId(R.id.edittext), withParent(withId(R.id.name_container)))).check(matches(isDisplayed())).perform(click()); 我得到的错误信息是: a
视图
类公共类Foo扩展了RelativeLayout{…}
,其中有一个EditText
。Foo
类有一个膨胀的XML布局,其EditText
也有一个id,但它无法找到EditText
我用的是浓缩咖啡代码:
onView(allOf(withId(R.id.edittext), withParent(withId(R.id.name_container)))).check(matches(isDisplayed())).perform(click());
我得到的错误信息是:
android.support.test.espresso.NoMatchingViewException:中没有视图
找到匹配的层次结构:(id:dk.aura.app.staging:id/edittext)
并且具有父匹配项:id为:
dk.aura.app.staging:id/name_容器)
我坚持不懈地找到了自己问题的答案 似乎在访问另一个视图(嵌套视图)中的视图时,必须检查它是否
是descendatofa()
,而不是withParent()
所以这是正确的方法:onView(allOf(withId(R.id.edittext),isdescendatofa(withId(R.id.name_container)))。检查(匹配项(isDisplayed())代码>