0

I'm trying to get the dragging function to work on my recyclerView but only the swiping works at the moment.

I only have the basic code which as far as I understand should enable the action

ItemTouchHelper helper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN,
                ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
            @Override
            public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder dragged, @NonNull RecyclerView.ViewHolder target) {


                return false;
            }

            @Override
            public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {

            }
        });
        helper.attachToRecyclerView(recyclerView);

And this code relates to the .XML file below

<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:clickable="true">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/historyView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="true"
        android:clickable="true"
        /> </androidx.constraintlayout.widget.ConstraintLayout>

It such a simple thing that I'm very confused as to why it wouldn't be working since the swiping works flawlessly. I can't seem to find anyone else who stumbled upon the same issue.

null_override
  • 467
  • 3
  • 10
  • 30
bonktlm
  • 1
  • 1

1 Answers1

0

try this

@Override
public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
    if (viewHolder instanceof CartAdapter.MyViewHolder) return 0;
    return super.getSwipeDirs(recyclerView, viewHolder);
}
Alireza
  • 446
  • 4
  • 15