gpt4 book ai didi

android - 回收器向左滑动和向右滑动执行不同的操作

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:57:37 25 4
gpt4 key购买 nike

我有以下回收器 View 代码,允许用户向右滑动(从 View 中删除卡片并从 SQLite 数据库中删除数据),还允许用户移动标签以重新排列。有用。我很高兴。

ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN,  ItemTouchHelper.RIGHT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
//awesome code when user grabs recycler card to reorder
}

@Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
super.clearView(recyclerView, viewHolder);
//awesome code to run when user drops card and completes reorder
}

@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
//awesome code when swiping right to remove recycler card and delete SQLite data
}
};
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
itemTouchHelper.attachToRecyclerView(recyclerView);

现在,我想添加向左滑动并执行与向右滑动不同的操作的功能。到目前为止我找到的所有解决方案都需要重写我的代码。有任何关于将 SWIPE LEFT 添加到我现有代码的建议吗?

最佳答案

onSwiped方法上,添加-

if (direction == ItemTouchHelper.RIGHT) {
//whatever code you want the swipe to perform
}

然后向左滑动另一个-

if (direction == ItemTouchHelper.LEFT) {
//whatever code you want the swipe to perform
}

关于android - 回收器向左滑动和向右滑动执行不同的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42875299/

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