RecyclerView ItemTouchHelper Action Drag Ended

后端 未结 2 1607
太阳男子
太阳男子 2021-02-05 08:17

I need to listen to the user when he stops drag and drop on my RecyclerView (when he drops the selected item).

Can I get this Information through my Ite

2条回答
  •  隐瞒了意图╮
    2021-02-05 08:51

    You can override onSelectedChange in your implementation of ItemTouchHelper.Callback(), such as:

     override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
            super.onSelectedChanged(viewHolder, actionState)
            when (actionState) {
                ItemTouchHelper.ACTION_STATE_DRAG ->
                    Log.d("DragTest","Start to drag: $actionState")
                ItemTouchHelper.ACTION_STATE_SWIPE ->
                    Log.d("DragTest","Start to swipe: $actionState")
                ItemTouchHelper.ACTION_STATE_IDLE -> {
                    Log.d("DragTest","End action: $actionState")
                }
            }
        }
    

提交回复
热议问题