0

In pure Java there is MouseInputListener which I can use to work with those 2 events.

How do I do it with Android?

If I implement both events then only one is fired (onClickListener) and not the other.

Updated:

The question is not about detecting the finger movement.

I have a View (ImageView for example). I need to detect the click on this view which is onClickListener() and finger movement on this view (i.e. press, move then release the finger).

The problem here is that only onClickListener() is called and MotionEvent handler is not caught.

I need to be able to differentiate those 2 events as the main event should be finger movement and onClickListener() should just say "Don't click this view. Spin this view."

Hopefully this is more clear.

Kev
  • 118,037
  • 53
  • 300
  • 385
Igor
  • 5,620
  • 11
  • 51
  • 103

1 Answers1

0

OnClickListener and OnTouchListener kinda obstruct each other, since they both consume the MotionEvents that get caught on the View.

Basically you can write a single OnTouchListener that checks for both things. You'll get supplied with the MotionEvent as an argument. Check it's action via MotionEvent.getAction(), e.g. if it equals MotionEvent.ACTION_DOWN (the user put the finger on the display). If the user releases the finger at approx. the same position (ACTION_UP), you may want to interpret that as a click. Otherwise interpret the positions that you get with the ACTION_MOVE event as a gesture.

But the framework already has some classes that do this interpreting work for you, check out the SimpleGestureDetector class and it's SimpleOnGestureListener. That has some callbacks for common events, e.g. onSingleTapConfirmed() and onFling(). All you need to do is supply the MotionEvents from your OnTouchListener to the GestureDetector.

  • Glad I could help. Please mark this as the [correct answer](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) if it was helpful. *(Since you are new to SO you may not be aware of that mechanism)* –  Sep 19 '11 at 22:21