gpt4 book ai didi

android - 如何禁用拉动刷新,滑动回收器查看项目时?

转载 作者:行者123 更新时间:2023-11-29 18:33:27 25 4
gpt4 key购买 nike

我在 SwipeRefreshLayout 中使用 recyclerview,当我开始滑动以删除我的 recycler View 项目时,它将主动拉动以刷新。我想在开始滑动时禁用拉动刷新并启用完成的滑动。我使用 ItemTouchHelper 类来检测滑动 Action

这是我的 .xml 文件

<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</RelativeLayout>

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

然后,这个 Java 文件,

 new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
@Override
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
return false;
}

@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {

}
}).attachToRecyclerView(recyclerView);

最佳答案

new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
@Override
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
return false;
}

@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {

}

@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
super.onSelectedChanged(viewHolder, actionState);
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
swiperefreshLayout.setEnabled(false);
} else {
swiperefreshLayout.setEnabled(true);
}
}
}

关于android - 如何禁用拉动刷新,滑动回收器查看项目时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55204629/

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