1

I already have an OnClickListener when clicking on a RecyclerView item to open a new Activty. Now, I want to implement OnDoubleTap listener as well, but I'm not sure how.

Do I have to create a GestureDetector in the ViewHolder? On the other hand, isn't the RecyclerView gonna intercept the onTouch event because of the scroll?

Dani M
  • 1,173
  • 1
  • 15
  • 43

1 Answers1

0

Yes, best way to achieve this is by using GestureDetector. See sample code:

https://developer.android.com/samples/BasicGestureDetect/src/com.example.android.basicgesturedetect/GestureListener.html

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Onur Çevik
  • 1,560
  • 13
  • 21
  • Yeah, but, is it gonna work along with the OnClickListener? – Dani M Feb 09 '16 at 23:44
  • I removed the OnClickListener and It does not work. Maybe the RecyclerView intercepts the onTouch events? In my MainActivity I use the dispatchTouchEvent method, but I cannot use it in the adapter. How can I solve it? – Dani M Feb 10 '16 at 12:38
  • @cuoka give onSingleTapConfirmed method a try. I think it would be better to use instead of a regular onClick, since it let's your app distunguish between a double tap or a single tap. You need to extend GestureDetector.SimpleOnGestureListener class to use that method. I haven't used it, but I think it will give you just a small delay compared to onClick, yet a better click support. – Onur Çevik Feb 10 '16 at 12:42
  • Yeah, I tried it, but these touch events are not getting called, and I'm using the same code as in the MainActivity, which is working fine. Can you please provide me an example code? – Dani M Feb 10 '16 at 12:57
  • @cuoka see this: http://www.learn-android-easily.com/2013/06/android-gesturedetector-example.html – Onur Çevik Feb 10 '16 at 12:59
  • @cuoka glad to hear it – Onur Çevik Feb 10 '16 at 13:56