I have a RecyclerView in my app and it displays data. I want to disable user touch events of RecyclerView. I have tried the below code but it does not work.
recyclerView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
});
Please help me.
you can use RecyclerView function
public void setLayoutFrozen(boolean frozen)
Java:
Kotlin:
Just use this, fixed my problems (;
As I had a similar use case a few days ago and stumbled upon this question just now:
you can add either
RecyclerView.SimpleOnItemTouchListener
RecyclerView.OnItemTouchListener
to your RecyclerView.
Example using
RecyclerView.SimpleOnItemTouchListener
:I consumed the touch event while my
SwipeRefreshLayout
was doing background work by queryingswipeLayout.isRefreshing()
.If you return
true
touch events are disabled.if Return
false
touch events are enable.hope it helps..
You can override the LinearLayoutManager
canScrollHorizontally
method