Search code examples
androidandroid-recyclerviewandroid-viewpager2

How to prevent scrolling or any user input on a RecyclerView in viewpager2


The recyclerview is in a fragment (1) and work perfectly fine but when I'm using a ViewPager2 to show another fragment (2) on top of the previous fragment (1), the recyclerview from fragment (1) still react (to scrolling for example).

How I can prevent that on a viewpager2 structure? I'm afraid if later I add listener on RecyclerView item, those could be triggered by mistake when using the fragment (2).


Solution

  • Add android:focusable="true" and android:clickable="true" in your fragment2 xml root view. This will get the focus if you click background