BaseRecyclerViewAdapterHelper 拖拽,只改变两个item的位置,其他位置不变,怎么处理呢

zaq34kh6  于 2022-10-27  发布在  其他
关注(0)|答案(4)|浏览(585)
  • No description provided.*
atmip9wb

atmip9wb2#

https://liangjingkanji.github.io/BRV/drag.html

大佬这个不行哦,我需要的是,拖拽1到5的位置,5的item就在1的位置,1在5的位置,而不是1到5,

mefy6pfw

mefy6pfw3#

class DraggableModuleService(private val baseQuickAdapter: BaseQuickAdapter<*, *>) :
BaseDraggableModule(baseQuickAdapter) {
val TAG = "DraggableModuleService"

override fun onItemDragMoving(
    source: RecyclerView.ViewHolder,
    target: RecyclerView.ViewHolder
) {
    Log.i(TAG, "onItemDragMoving: ")
    if (target.layoutPosition>4){
        super.onItemDragMoving(source, target)
    }else{
        //自己的排序规则
    }
}

}

重新设置draggableModule

DraggableModuleService draggableModule = new DraggableModuleService(mAdapter);
    draggableModule.setItemTouchHelperCallback(new DragAndSwipeCallback(draggableModule));

    draggableModule.attachToRecyclerView(mRecyclerView);
    draggableModule.setDragEnabled(true);
zz2j4svz

zz2j4svz4#

class DraggableModuleService(private val baseQuickAdapter: BaseQuickAdapter<*, *>) :
BaseDraggableModule(baseQuickAdapter) {
val TAG = "DraggableModuleService"

override fun onItemDragMoving(
    source: RecyclerView.ViewHolder,
    target: RecyclerView.ViewHolder
) {
    Log.i(TAG, "onItemDragMoving: ")
    if (target.layoutPosition>4){
        super.onItemDragMoving(source, target)
    }else{
        //自己的排序规则
    }
}

}

重新设置draggableModule

DraggableModuleService draggableModule = new DraggableModuleService(mAdapter);
    draggableModule.setItemTouchHelperCallback(new DragAndSwipeCallback(draggableModule));

    draggableModule.attachToRecyclerView(mRecyclerView);
    draggableModule.setDragEnabled(true);

大佬,不是交换1和5的位置,是我表达不够好,其实是想只交换拖动的item和拖动到该item的位置互换,其他不变,移动不要交换,松手后才交换

相关问题