gpt4 book ai didi

android - 在 RecyclerView 中获取 TextView 的文本 - android 仪器测试

转载 作者:行者123 更新时间:2023-12-03 17:39:55 25 4
gpt4 key购买 nike

我有一个包含 item.xml 项目的 RecyclerView。
在 item.xml 我有一个 TextView。

我正在创建一个仪器测试,并想知道如何从 recyclerView 的那个 textview 中获取文本,以便我可以用它做一些额外的工作。

使用 https://spin.atomicobject.com/2016/04/15/espresso-testing-recyclerviews/我设法检查了我所期望的文本是否是我所期望的,但我也需要得到这个值。

错误代码:

descendant: with string from resource id: <2131427419>' doesn't match the selected view when calling onView(withRecyclerView(R.id.recycler_view).atPosition(2)) .check(matches(hasDescendant(withText(R.id.my_textview))));

最佳答案

尝试这个

String title = ((TextView) recyclerView.findViewHolderForAdapterPosition(position).itemView.findViewById(R.id.my_textview)).getText().toString();

关于android - 在 RecyclerView 中获取 TextView 的文本 - android 仪器测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38873784/

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