Event bubbles do not appear in RecyclerView

I am wondering why click events do not bubble if I click inside RecyclerView .

My script uses a simple RecyclerView to show some TextView s, while its parent View has a registered OnClickListener to perform some action if someone clicks on the view. If I click, for example. a TextView event of a click event correctly up to parent. But if I click on RecyclerView , the click will not start bubbling. It is strange that if I install OnClickListener directly on the RecyclerView , it also does not start. I guess this is the root of all evil.

So why is my RecyclerView not getting any click events? Why does the parent not receive click events?

The hierarchy is as follows:

 - View (has an OnClickListener) <- Why no clicks? - RecyclerView (clickable=false) - TextView - TextView .... 

I experimented with setFocusable() and setClickable() , but with no luck.

PS: My current solution sets OnClickListener for each TextView inside RecyclerView and uses getParent() to distribute the click on the parent view using performClick() manually.

+5
source share
1 answer

I use a special class handler for RecyclerView , RecyclerView.OnItemTouchListener . I can add from the consumption class. Here is the default implementation of the handler class:

recyclerView.addOnItemTouchListener (new RecyclerView.OnItemTouchListener () {

  @Override public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { //Put your code here. //Called 2 times per touch, on pressdown and on release. return false; //true will disable scroll view. } @Override public void onTouchEvent(RecyclerView rv, MotionEvent e) { setDefaultBottomBar(); } @Override public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { } }); 
0
source

Source: https://habr.com/ru/post/1208121/


All Articles