Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reorder items in recyclerView without long press

I implemented the reorder of items in recyclerView using itemTouchHelper.callback as it seems to be the most popular solution now. However this allows to reorder only after long press on any item and I need to be able to freely move items around any time (I attach item itemTouchHelper for 'edit mode' and detach right after. What is the easiest way to achieve that?

like image 455
cherepets Avatar asked Apr 27 '18 08:04

cherepets


1 Answers

first of all disable LongPressDragEnabled in itemTouchHelper and then just call startDrag(RecyclerView.ViewHolder) from on touch of your custom handle view ie Imageview or anything like this

viewHolder.dragButton.setOnTouchListener(new View.OnTouchListener() {
         public boolean onTouch(View v, MotionEvent event) {
             if (MotionEvent.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
                 mItemTouchHelper.startDrag(viewHolder);
             }
             return false;
         }
     });
like image 191
Zealous System Avatar answered Sep 30 '22 00:09

Zealous System