Make Lists Magical with RecyclerView's ItemTouchHelper
https://youtu.be/6Dw3KbQznhY ItemTouchHelper was added to RecyclerView back in 22.2 and adds a lot of power to responding to touch events in RecyclerViews.
canDropOver(RecyclerView recyclerView, RecyclerView.ViewHolder current, RecyclerView.ViewHolder target) { return true; // maybe a header View or other circumstance to be false. } public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target)
ADAPTER. • DIRECTION IS VERY USEFUL. • AS SIMPLE AS: @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { // update data here! adapter.notifyItemRemoved(viewHolder.getAdapterPosition()); // notify adapter. } public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction)
float animateDy); public float getSwipeThreshold(RecyclerView.ViewHolder viewHolder) public float getMoveThreshold(RecyclerView.ViewHolder viewHolder); public float getSwipeEscapeVelocity(float defaultValue); public float getSwipeVelocityThreshold(float defaultValue); public int getBoundingBoxMargin();
RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive); public void onChildDrawOver(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive); WITH SOME MORE HELP