gpt4 book ai didi

android - UiAutomator 访问信息有限的 child

转载 作者:行者123 更新时间:2023-11-30 03:16:43 25 4
gpt4 key购买 nike

我有一个动态构建的 View 列表,因此它们都具有完全相同的资源 ID,但没有描述。我可以区分它们之间区别的唯一方法是同一父级中的文本。我在想唯一的办法就是这样做:

Child >> parent >> child

enter image description here

正如您在上面看到的,我可以获得子项 MILESCALORIES。我需要从大量的文本中获取文本。

最佳答案

可以从大量 View 中获取文本。假设布局是:

1. RelativeLayout
0. Text View -> MILES
1. Text View -> 0.50
2. RelativeLayout
0. Text View -> CALORIES
1. Text View -> 100

UiCollection resultsPage = new UiCollection(
new UiSelector().className(android.widget.ListView.class.getName()));
UiObject resultLayout = resultsPage
.getChildByText(new UiSelector()
.className(android.widget.RelativeLayout.class
.getName()), text); //where text can be MILES or CALORIES
UiObject score = resultLayout.getChild(new UiSelector()
.resourceId(the resource id for the large text));
return (String) score.getText();

想法是隔离两个 Relative 布局并搜索其中的文本,而不是整个 GUI。您可以使用 uiautomatorviewer 查看 GUI 布局。也许您可以使用详细布局更新问题。

我可以使用它来给出更准确的答案。

关于android - UiAutomator 访问信息有限的 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19964757/

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