I have this code which implements a RecyclerView and I want to add to it some gestures. I want 2 things to do and I don't know because I'm new to this.
When someone clicks on
RecyclerViewI want to catch the event from theActivitybefore goes down to recycler. That's why I return true fromdispatchTouchEvent. But it does not work because onTouch is called.In case we allow the event to pass down, when the touch event goes to recycler (OnTouch Method),
Activity'sonTouchEventis not called. It is supposed to be called because the event handling bubbles up.public class MainActivity extends AppCompatActivity implements View.OnTouchListener{ private RecyclerView recyclerView; private GestureDetectorCompat detector; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); detector = new GestureDetectorCompat(this, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onFling (MotionEvent e1, MotionEvent e2,float velocityX, float velocityY){ return false; } }); recyclerView.setOnTouchListener(this); } @Override public boolean onTouchEvent(MotionEvent event) { return detector.onTouchEvent(event); } @Override public boolean onTouch(View v,MotionEvent event) { return detector.onTouchEvent(event); } @Override public boolean dispatchTouchEvent(MotionEvent ev){ super.dispatchTouchEvent(ev); return true; } }