Event trigger and transfer mechanism in Android Activity and ViewGroup, androidviewgroup

Source: Internet
Author: User

Event trigger and transfer mechanism in Android Activity and ViewGroup, androidviewgroup

1. When only Activity is available:

1) Touch event trigger process:

First, trigger dispatchTouchEvent and then trigger onUserInteraction again. If onTouchEvent is clicked, follow the following events (Click ACTION_DOWN and ACTION_up in two steps) trigger dispatchTouchEvent again onTouchEvent when ACTION_up event does not trigger onUserInteraction (you can view the source code)

2) keyboard event triggering Process

First, trigger dispatchKeyEvent and then trigger onUserInteraction again onKeyDown. If you press and then release it, the two steps are followed to trigger the dispatchKeyEvent and then trigger onUserInteraction again onKeyUp. Note that onUserInteraction is triggered when you release the key.

In short: Activity. dispatchTouchEvent (MotionEvent)-This allows your Activity to capture all touch events before being distributed to the window. (Similarly, dispatchKeyEvent)

 

2. There is a Layout in the Activity and a button in Layout:

If a CLICK event is triggered on the button, the event transmission process is as follows:

First, trigger the dispatchTouchEvent of the ACTIVITY, then trigger the onUserInteraction of the ACTIVITY, then trigger the dispatchTouchEvent of LAYOUT, then trigger the onTouch (this is an ACTION_DOWN event) of the BUTTON) it is followed by the dispatchTouchEvent of the ACTIVITY triggered by an ACTION_UP event. Note that the onUserInteraction of the ACTIVITY will not be triggered because it does not work for ACTION_UP. Then, the dispatchTouchEvent of LAYOUT is triggered, the onInterceptTouchEvent of LAYOUT is triggered, the onTouch of the BUTTON is triggered, and The onClick of the BUTTON is finally triggered. if you return true in the ONTOUCH event and consume the event, The ONCLICK event will not be responded. However, if you do not write The ONCLICK event, the ONTOUCH event will return FLASE.

3. Summary:

Android event triggering process:

-------------------------------------------------------------------

First, trigger the dispatchTouchEvent of the ACTIVITY.

Then, the onUserInteraction of the ACTIVITY is triggered.

Then, the dispatchTouchEvent of LAYOUT is triggered.

Then, the onInterceptTouchEvent of LAYOUT is triggered.

-------------------------------------------------------------------

  

  

  

Related Article

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.