RecyclerView ItemTouchHelper Drag and Drop Action

I need to listen to the user when he stops dragging and dropping my RecyclerView (when he drops the selected item).

Can I get this information through my ItemTouchHelper?

thanks for the help

Note: At the moment, I am only now when the user is still moving the item :)

@Override public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) { if (source.getItemViewType() != target.getItemViewType()) { return false; } // Notify the adapter of the move mAdapter.onItemMove(source.getAdapterPosition(), target.getAdapterPosition()); return true; } 
+7
android gesture gesturedetector android-recyclerview
source share
1 answer

UPDATED

You can first determine where you can delete an object by implementing canDropOver

 @Override public boolean canDropOver(RecyclerView recyclerView, RecyclerView.ViewHolder current, RecyclerView.ViewHolder target) { return current.getItemViewType() == getItemViewType(); } 

Update the adapter you want to use onMove , which you can call several during the drag operation

 @Override public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { adapter.moveItem(viewHolder.getAdapterPosition(), target.getAdapterPosition()); return true; } 

To determine when interaction with an element is exceeded, implement clearView , this is for any type of action (drag and drop), even if it was successful (the element is moved or scrolled) or canceled (the element is not moved or not shifted)

 @Override public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { super.clearView(recyclerView, viewHolder); // Action finished } 
+8
source share

All Articles