Android: Why does long click also trigger a normal click?

mellowg picture mellowg · Mar 25, 2011 · Viewed 45.2k times · Source

I have a ListView with listeners for a long click and a regular click.

Why, when I long press a list item, the regular click event gets called too?

I need to have two separate functions for the different clicks.

Answer

erichamion picture erichamion · Mar 25, 2011

From Event Listeners:

onLongClick() - This returns a boolean to indicate whether you have consumed the event and it should not be carried further. That is, return true to indicate that you have handled the event and it should stop here; return false if you have not handled it and/or the event should continue to any other on-click listeners.

Are you returning true from your onLongClick() and still getting the normal click event?

Edited to add: For a ListView, you may be using OnItemLongClickListener. The onItemLongClick() there uses a similar boolean return value to indicate whether it consumed the event.