android - 如何滚动 Recycler 视图并从每张卡片中收集文本?
问题描述
基本上我需要滚动浏览回收站视图并从每张卡片或单元格中收集数据,
我试过使用 RecyclerViewActions.scrollToPosition 像,
- 获得了 Recycler 视图的总数
- 使用 RecyclerViewActions.scrollToPosition 从 0 滚动到总数
- 使用本地列表视图计数中的索引从卡片或单元格中获取文本
是的,它有时可以工作,但是每次卡的大小不同时它都不能工作
是否有任何其他方式可以滚动并从每张卡片中获取文本或任何其他方式在所有情况下都能完美运行?
我试过的代码:
public int countofRecyclerView(int id){
RecyclerView recyclerView=getCurrentActivity().findViewById(id);
return recyclerView.getAdapter().getItemCount();
}
public int localListviewcount (int listViewId) {
onView(withId(listViewId)).check(matches(allOf(isCompletelyDisplayed(), isFocusable(), new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {}
@Override
protected boolean matchesSafely(View item) {
if (item instanceof RecyclerView) {
listCount = ((RecyclerView) item).getChildCount();
} else if (item instanceof ListView) {
listCount = ((ListView) item).getChildCount();
}
return true;
}
})));
return listCount;
}
int totalCount=countofRecyclerView(id.recyclerview)
ArrayList<String>ab=new ArrayList<>()
int index=0
for(int i=0;i<totalCount;i++){
onView(id.recyclerview).perform(RecyclerViewActions.scrollToPosition(i));
int j=localListviewcount(id.recyclerview)
if(i<j){
index=j
}else{
index=i
}
ab.add(getTextfromId(id, index))
}
解决方案
推荐阅读
- javascript - 如何使用钩子在 React 中实现这个倒数计时器?
- swift - Swift Tab Bar 变黑而不是消失
- firebase - Flutter Firestore 如何将数组从firestore加载到列表中
- html - 我的导航元素之间的空间不会适应视口
- javascript - 你会如何推荐procced?
- root - 修复我一直像普通用户一样使用 root 的 Arch 系统
- javascript - 在 Firefox 中点击事件数据未发送到 Google Analytics
- macos - 以下位置的路径名是什么?
- python - Django Cron 包最新版本未在指定时间运行
- c++ - 在 macOS 10.15.6 上编译 Apache ORC 时出错