Stepping on the pit - the control click is invalid after using dispatchTouchEvent

After using dispatchTouchEvent, the control click is invalid

origin

To deal with the touch event distribution, the requirement is to monitor and realize clicking on other areas to hide the input box, but I found that my clear button cannot be used after entering text. Let us analyze the reason below.

insert image description here

Source code analysis

After description: If the ivButton is in the displayed state, it is possible to click the clear button. On the contrary, if the ivButton is in the hidden state, it is invalid to click the clear button. Then why is this?
The reason is because ivButton returns false if it is in the display state, otherwise it returns true.
If showView(ev) returns true, dispatchTouchEvent returns true, otherwise dispatchTouchEvent returns super.dispatchTouchEvent(ev),
then dispatchTouchEvent returns true and super.dispatchTouchEvent (ev) What is the difference , let's look down

insert image description here

analyze

After reading some articles and materials, I came to the conclusion:
Once dispatchTouchEvent returns true, it indicates that the event has been consumed and no longer distributes the event
( note: except for dispatchTouchEvent of Activity, which returns true/false to indicate that the event has been consumed, only return super.dispatchTouchEvent (ev) is passed down)

Guess you like

Origin blog.csdn.net/Mr_Gaojinchao/article/details/128168871