Talk about the relationship between ontouch and onclick events in Android (required)

I have encountered some touch events related to Android these days, and also related to onclick. Let's write down for the moment:

LinearLayout sets ontouchlistener, onclicklistener, onlongclicklistener and ontouchevent callbacks respectively

@H_ 419_ 5@1 . after touching on the screen, the basic execution process is as follows:

That is, the ontouchlistener is triggered first, and then the ontouchevent callback itself; Onclicklistener will not be triggered until the last up event occurs and is processed by ontouchevent.

@H_ 419_ 5@2 . remove the super.ontouchevent from the ontouchevent callback and directly return true; The process is as follows:

You can see that onclicklistener can never be triggered, which also shows that the triggering of onclick is implemented in the ontouchevent callback.

@H_ 419_ 5@3 Press and hold the screen, and the process is as follows:

When you press and hold, the response of onlongclick will be triggered without going to up, but the response of onclick will continue to be triggered later.

@H_ 419_ 5@4 . however, if true is returned in onlongclick, the process is as follows: onlongclick is triggered only in the middle, and then touch will continue to respond, but onclick will not be triggered when up

The test code is as follows:

The above detailed discussion on the relationship between ontouch and onclick events in Android (must see) is all that Xiaobian has shared with you. I hope it can give you a reference and support more programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>