android--Android Event Mechanism II: Ontouch detailed

Source: Internet
Author: User

Android Event Mechanism II: Ontouch detailed

In the summary of the ontouchevent, it is not very specific. This article will mainly summarize the Ontouch.

Ontouch is the basis of the entire event mechanism in the Android system. Other events in Android, such as OnClick, Onlongclick, etc., are based on Ontouch.

The ontouch includes the entire process from the finger press to the left-hand screen, in microscopic form, in the Action_down, Action_move, and action_up processes.

Ontouch two main definition forms are as follows:

(1) In custom controls, there is a common rewrite ontouchevent (motionevent ev) method. And there are corresponding judgements for different microscopic manifestations (Action_down, action_move, and action_up, etc.) that execute the logic and may return different Boolean values.

(2) in the code, set the Setontouchlistener listener directly to the existing control. and rewrite the listener's Ontouch method. The Ontouch callback function has the view and Motionevent parameters , which can also be processed differently for different event micro-manifestations.

It is important to note that, overall, the micro-performance of the event follows the article "event delivery and consumption," but for Action_down, there are a few things to note:

1. In all the microscopic manifestations of events, Action_down is the basis of the whole event and is the starting event of any macro event

Once Action_down return False, indicates that the event continues to bubble, when there is a layer of Action_down return true, indicating that this layer consumes this action_down event, then in the next Action_move, In events such as ACTION_UP, the event will not continue to bubble to the outer layer, regardless of whether Action_move,action_up, etc. return False or True. The event was then consumed.

2. It can be learned that Action_down plays an important role in the whole event. If Action_move or ACTION_UP micro-events occur in a certain layer, the Action_down microscopic events occur.

About Setontouchlistener, Setonclicklistener and Setonlongclicklistener:

In Android, it is sometimes common to see that different event listeners (such as Setontouchlistener, Setonclicklistener, and Setonlongclicklistener) may be set for the same control.

Setontouchlistener is the first to execute the order in which these event listeners are executed.

It is possible to invoke the PerformClick() method, which is called the onclick () execution, only after the secondary control has completed the Action_down and action_up processes.

The Onlongclick is started after Action_down, and is in a new thread to determine the time of the press, the condition satisfies the call Performlongclick () method, that is called The onlongclick () function.

android--Android Event Mechanism II: Ontouch detailed

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.