在做点击按钮的时候经常会同时监听点击事件和长点击事件,有时在触发长点击事件的时候会同事触发点击事件
Public Methods
public abstract boolean onLongClick ( View v)
Added in API level 1
Called when a view has been clicked and held.
Parameters
v | The view that was clicked and held. |
---|
Returns
- true if the callback consumed the long click, false otherwise.
说明了如果返回值为true的话这个点击事件会被长点击独占,否则相反。
这下就可以理解了为什么之前的点击会同时触发两个点击事件。
将onLongClick的返回值设置为true,即可避免这个问题的发生。