Android View key Event distribution process OnTouch ontouchevent onclick Onlongclick and OnKey onKeyDown onclick

Source: Internet
Author: User

1. In order to test, we also set the view OnTouch ontouchevent OnClick onlongclick four events, after the printing test found that the key distribution process is this if the short press:ontouch-->> Ontouchevent--->>onclick. Long press: ontouch-->>ontouchevent--->>onlongclick-->>onclick. Why would that be?


We look at the view source

public boolean dispatchtouchevent (Motionevent event) {        if (minputeventconsistencyverifier! = null) {            Minputeventconsistencyverifier.ontouchevent (event, 0);        }        if (onfiltertoucheventforsecurity (event)) {            //noinspection simplifiableifstatement            listenerinfo li = Mlistenerinfo;            if (Li! = null && Li.montouchlistener! = null && (mviewflags & enabled_mask) = = ENABLED                    && Li.mOnTouchListener.onTouch (this, event)) {                return true;            }            if (Ontouchevent (event)) {                return true;            }        }        if (minputeventconsistencyverifier! = null) {            minputeventconsistencyverifier.onunhandledevent (event, 0);        }        return false;    }

Analysis: In the event distribution method, first execute

if (Li! = null && Li.montouchlistener! = null && (mviewflags & enabled_mask) = = ENABLED                    && Li.mOnTouchListener.onTouch (this, event)) {                return true;            }

If the OnTouch return value is true, then the event is consumed here. The event is not distributed, the Ontouchevent event is not executed, and subsequent events are not executed. If the Ontouch return value is False, the event continues to be distributed, executing
if (Ontouchevent (event)) {                return true;            }

The Onlongclick event is then executed before the onclick event is executed. As long as the previous key event is not consumed, the event will continue to be distributed. Until the end of consumption.


2. Similarly to the view set OnKey OnKeyDown OnClick and other events, the same distribution process is: OnKey-->>onkeydown--->>onclick, originally ibid.

Records are for ease of reference only.

Android View key event distribution process OnTouch ontouchevent onclick Onlongclick and OnKey onKeyDown onclick

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.