@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
// Set movement flags based on the layout manager
if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
final int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
final int swipeFlags = 0;
return makeMovementFlags(dragFlags, swipeFlags);
} else if (viewHolder instanceof ItemTouchHelperViewHolder) {
//Only ViewHolder implents ItemTouchHelperViewHolder can be draged.
final int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
final int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
return makeMovementFlags(dragFlags, swipeFlags);
} else {
//others can not be draged.
final int swipeFlags = 0;
final int dragFlags = 0;
return makeMovementFlags(dragFlags, swipeFlags);
}
}
@Override public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { // Set movement flags based on the layout manager if (recyclerView.getLayoutManager() instanceof GridLayoutManager) { final int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT; final int swipeFlags = 0; return makeMovementFlags(dragFlags, swipeFlags); } else if (viewHolder instanceof ItemTouchHelperViewHolder) { //Only ViewHolder implents ItemTouchHelperViewHolder can be draged. final int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN; final int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END; return makeMovementFlags(dragFlags, swipeFlags); } else { //others can not be draged. final int swipeFlags = 0; final int dragFlags = 0; return makeMovementFlags(dragFlags, swipeFlags); } }