I want to implement a long press of a CardView inside a RecyclerView
The layout:
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:scrollbars="vertical"
android:longClickable="true"
android:hapticFeedbackEnabled="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
I tried this:
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(Utils.context));
mRecyclerView.setOnLongClickListener(new AdapterView.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
Toast.makeText(Utils.context,"dsfd",Toast.LENGTH_LONG).show();
return true;
}
});
And I also tried to implement this event in the RecyclerView.ViewHolder class but nothing works. I have the long press effect but the event itself is not triggered. There is no onItemLongClickListener. I also tried this: RecyclerView onClick .
What am I missing?