gpt4 book ai didi

android - 删除所选单元格的拖放

转载 作者:行者123 更新时间:2023-11-29 23:07:19 25 4
gpt4 key购买 nike

我已经为我的回收站 View 创建了拖放操作,但我想在拉取单元格时禁用拖放选项(在我的 View 中它是一个标题)。如何使它们不能用于拖放功能?

拖放助手

class SimpleItemTouchHelperCallback(private val mAdapter: ItemTouchHelperAdapter) : ItemTouchHelper.Callback() {
override fun isLongPressDragEnabled() = true

override fun isItemViewSwipeEnabled() = true

override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {}

override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int {
val dragFlags = ItemTouchHelper.UP or ItemTouchHelper.DOWN
val swipeFlags = ItemTouchHelper.START or ItemTouchHelper.END

return ItemTouchHelper.Callback.makeMovementFlags(dragFlags, swipeFlags)
}

override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
mAdapter.onItemMove(viewHolder.adapterPosition, target.adapterPosition)

return true
}
}

Recyclerview 适配器

interface ItemTouchHelperAdapter {
fun onItemMove(fromPosition: Int, toPosition: Int): Boolean
}

将适配器与 rv 配对的代码

val drugAndDropHandler = SimpleItemTouchHelperCallback(adapter)
ItemTouchHelper(drugAndDropHandler).attachToRecyclerView(multiple_stores_list)

最佳答案

只需要覆盖getMovementFlags

override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int {
if (viewHolder.adapterPosition in 0..NOT_DRAGABLE_ITEMS_MAX_POSITION) {
return 0
}
}

关于android - 删除所选单元格的拖放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56396015/

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