gpt4 book ai didi

android-espresso - 在 Espresso 中单击 ListView 的特定子项

转载 作者:行者123 更新时间:2023-12-04 16:10:31 25 4
gpt4 key购买 nike

使用 Espresso,我希望能够单击 ExpandableListView(名为 CustomExpandableView)的特定子项。 listview 创建一组RelativeLayouts(名为MyContainer)。

理想情况下,我想单击 CustomExpandableView 中的特定 MyContainer。但是,我可以只点击第一个。

MyContainer 对象没有我可以引用的唯一 ID,但它们的子对象有,例如- “文本=此处的示例文本 1”

我尝试了几种不同的变体,使用 onData 传递类类型并尝试让 child 处于特定位置,但它只是不起作用。而且,我想避免获取对象并对其进行迭代,直到找到合适的 child 。

这是 View 层次结构的一部分供引用(我从层次结构中删除了不重要的信息):

+----->CustomExpandableView{}
|
+-------->线性布局{}
|
+------->TextView{}
|
+------->框架布局{}
|
+-------->面包屑 View {}
|
+--------->图像按钮{}
|
+--------->TextView{}
|
+-------->线性布局{}
|
+------->我的容器{}
|
+-------->ImageView{res-name=thumb, }
|
+-------->ImageView{res-name=divider}
|
+-------->TextView{res-name=label, text=Sample Text Here 1, input-type=0, ime-target=false}
|
+------->我的容器{}
|
+-------->ImageView{res-name=thumb}
|
+-------->ImageView{res-name=divider}
|
+-------->TextView{res-name=label text=Sample Text Here 2, input-type=0, ime-target=false}
|

最佳答案

当您尝试使用 onData , Espresso 试图通过某些参数不查看 View ,但得到 AdapterListView并在此适配器中搜索数据(通过调用 Adapter#getItem )。

但是在 ExpandableListView 的情况下获取什么数据并不明显。
为此,Espresso 提供了 onData...().usingAdapterViewProtocol(AdapterViewProtocol) .这个方法javadoc说:
/**
* Use a different AdapterViewProtocol if the Adapter implementation does not
* satisfy the AdapterView contract like (@code ExpandableListView)
*/

这个 AdapterViewProtocol 接口(interface)看起来像:http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.0_r1/com/google/android/apps/common/testing/ui/espresso/action/AdapterViewProtocol.java .
AdapterViewProtocol 的示例实现:https://stackoverflow.com/a/40282991/1282732

正确定义后,onData将找到您搜索的项目 View 。之后,如果您需要对 child 执行操作或检查。你应该onData#onChildView .

关于android-espresso - 在 Espresso 中单击 ListView 的特定子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19695356/

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