I am trying to handle touch events and click events on a button. I do the following:
button.setOnClickListener(clickListener);
button.setOnTouchListener(touchListener);
When any one listener is registered things work fine but when I try to use them both only the touch events are fired. Any workaround? What am I doing wrong?
There is a subtle, yet very important difference between the
ClickListenerand theTouchListener. TheTouchListeneris executed before the view can respond to the event. TheClickListenerwill receive its event only after the view has handled it.So when you touch your screen, the
TouchListeneris executed first and when you returntruefor your event, theClickListenerwill never get it. But if you press the trackball of your device, theClickListenershould be fired because theTouchListenerwill not respond to it.