Android event trigger mechanism

Source: Internet
Author: User

First, this articleArticleIt is only applicable to events triggered by touch.

Android events: onclick, onscroll, onfling, and so on are composed of many touch events. The first status of touch must be action_down, indicating that the screen is pressed. Later, touch will have a follow-up event, which may be:

    • Action_move // indicates a mobile gesture.

    • Action_up // indicates leaving the screen

    • Action_cancel // indicates that the canceling gesture is not generated by the user, butProgramGenerated

One action_down, N action_move, and one action_up constitute many events in Android.

In Android, a type of control can also contain other child controls, which inherit from the viewgroup class, such as listview, gallery, and gridview.

Another type of controls cannot contain child controls, such as textview.

This article mainly discusses the trigger of nested event items of viewgroup controls.

An important method for viewgroup controls is onintercepttouchevent (), which is used to process events and change the transfer direction of events. Its return value is a Boolean value, determines whether the touch event needs to be passed to the Child view it contains. This method is to pass from the parent View to the Child view.

The ontouchevent () method is used to receive and process events. Its return value is also a Boolean value, which determines whether the event and subsequent events continue to pass up, this method is passed from the Child View to the parent view.

The transfer mechanism between onintercepttouchevent () and ontouchevent and each childview depends entirely on the return values of onintercepttouchevent () and ontouchevent. If the returned value is true, the event is correctly received and processed. If the returned value is false, the event is not processed and will be passed on.

The action_down event is uploaded to the onintercepttouchevent of a viewgroup class. If false is returned, the down Event continues to be passed to the onintercepttouchevent of the child viewgroup class. If the child view is not a control of the viewgroup class, the ontouchevent that is passed to it.

If onintercepttouchevent returns true, the ontouchevent that the down event is passed to it will not be passed, and subsequent events will also be passed to its ontouchevent.

If the ontouchevent of a view returns false, the down Event continues to be passed to the ontouchevent of its parent viewgroup class. If true is returned, subsequent events will be directly passed to its ontouchevent for further processing. (Subsequent events will only be passed to ontouchevent that returns true for the required event action_down)

To sum up, onintercepttouchevent can accept all touch events, while ontouchevent is not necessarily.

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.