Before doing the button click event has not noticed some details, today made a button need to have a click and long click Trigger different effects, directly let activity implements Onclicklistener, Onlongclicklistener then adds the corresponding handler function.
@Override publicvoid OnClick (View v) { // TODO auto-generated method Stub } @Override publicboolean Onlongclick (View v) { // TODO auto-generated method stub return false ; }
Without much consideration, I added the implementation I wanted directly within the function. In a casual test, I found that in my button click time there is a threshold, when I single-button time equal to this threshold, click events and long click events will simultaneously trigger. Click events naturally there is no problem, cause this problem must be a long click event out of the question, back to look closely at the method of long click event, found that it and click events basically no difference, the only difference is that there is a return value. So what's the use of this return value, check out the development documentation and describe the method as follows:
Public MethodsPublic Abstract Boolean Onlongclick (View v)Added in API Level 1
Called when a view has been clicked and held.
Parameters
| V |
The view is clicked and held. |
Returns
- True if the callback consumed the long click, False otherwise.
This indicates that if the return value is true, the Click event will be exclusive by a long click, otherwise the opposite.
This gives you an idea of why a previous click triggered two click events.
The
Set the return value of Onlongclick to true to prevent this problem from occurring.