Ragunath Jawahar Ragunath Jawahar - 1 year ago 84
Android Question

Can't handle both click and touch events simultaneously

I am trying to handle touch events and click events on a button. I do the following:


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?

Answer Source

There is a subtle, yet very important difference between the ClickListener and the TouchListener. The TouchListener is executed before the view can respond to the event. The ClickListener will receive its event only after the view has handled it.

So when you touch your screen, the TouchListener is executed first and when you return true for your event, the ClickListener will never get it. But if you press the trackball of your device, the ClickListener should be fired because the TouchListener will not respond to it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download