2

I want to implement the following behavior:

When the user starts to single-tap my View, highlight the View. When the user finishes the single-tap (releases the touch),stop highlighting the View. Just like with simple Buttons.

I tried to achive this with the onShowPress and onSingleTapConfirmed methods of SimpleOnGestureListener. Unfortunately, onShowPress does not get called at single-taps, but only at double-taps. How can i implement the desired behavior?

Thanks in advance!

WonderCsabo
  • 11,947
  • 13
  • 63
  • 105
  • 1
    [onDown](http://developer.android.com/reference/android/view/GestureDetector.SimpleOnGestureListener.html#onDown(android.view.MotionEvent)) instead of onShowPress maybe? > Notified when a tap occurs with the down MotionEvent that triggered it. This will be triggered immediately for every down event. All other events should be preceded by this. – Philippe A Mar 05 '14 at 10:47
  • The problem is my `View` is scrollable and zoomable, and `onDown` is also gets called while scrolling or zooming. – WonderCsabo Mar 05 '14 at 10:52

2 Answers2

0

Use drawable selectors with state lists and set it as the background for your view..

http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

Mark Buikema
  • 2,483
  • 30
  • 53
  • 1
    No, this is not a solution for me. I am using a canvas-based `View`, and i'm detecting gestures within that canvas. – WonderCsabo Mar 05 '14 at 14:03
0

Finally i used the onSingleTapUp method. So this called first, i highlight the View, then onSingleTapConfirmed gets called, then i turn off the highlight. I am sure this is not the best technique, feel free to share a better one.

WonderCsabo
  • 11,947
  • 13
  • 63
  • 105