The difference between Android ontouchevent and Setontouchlistener in Ontouch

Source: Internet
Author: User

Ontouchevent () method

is to get a variety of actions on the screen, such as swipe left and right, click the Back button, and so on.

belongs to a macro screen touch monitor.

Ontouchlistener () method
is to get the click-Monitoring of a particular view of a control.
Official document: Http://developer.android.com/ref ... ntouchlistener.html

The two are easy to distinguish.

The difference is as follows:

1, if the Ontouch method return value in Setontouchlistener is True (the event is consumed), then the Ontouchevent method will not be executed;

2. The Ontouchevent method is executed only if the return value of the Ontouch method in Setontouchlistener is False (the event is not consumed and is passed down).

3. The above-mentioned situation applies to the View object (the event is first responded to by the topmost view object) instead of the ViewGroup object (the event is first responded to by the outermost view object).

In general terms:

Ontouchlistener's Ontouch method has a higher priority than ontouchevent, which is triggered first.

If the Ontouch method returns False, the ontouchevent is then triggered, and the Ontouchevent method is not invoked.

Built-in implementations such as the Click event are based on Ontouchevent, and if Ontouch returns True, these events will not be triggered.


The difference between Android ontouchevent and Setontouchlistener in Ontouch

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.