android - Adding setOnTouchListener makes OnClickListener no longer working -
i have activity implements both ontouchlistener , onclicklistener. if add both listeners buttons, onclicklistener doesn't work, mean onclick() method, implemented in activity, doesn't anything.
i assign listeners in way.
button1.setonclicklistener(this); button1.setontouchlistener(this);
if remove
button1.setontouchlistener(this)
then onclick() method starts working.
the 2 listeners setting view:
onclick()
from view.onclicklistener. called when user either touches item (when in touch mode), or focuses upon item navigation-keys or trackball , presses suitable "enter" key or presses down on trackball.
and
ontouch()
from view.ontouchlistener. called when user performs action qualified touch event, including press, release, or movement gesture on screen (within bounds of item).
for ontouch()
,
ontouch() - returns boolean indicate whether listener consumes event. important thing event can have multiple actions follow each other. so, if return false when down action event received, indicate have not consumed event , not interested in subsequent actions event. thus, not called other actions within event, such finger gesture, or eventual action event.
to put simply, understanding, returning false avoids conflict ontouch action , onclick listener action.
something should go through:
input event listener interfaces
[..which have been part of research , d, maybe]
Comments
Post a Comment