I have a view on the screen that contains several view that in turn overlap each other.

I need to work only with the first one at the moment, for this I override the onInterceptTouchEvent() function, in every view inside the main view і in the main view redefine dispatchTouchEvent , where, according to the incoming event, I control the behavior of the current view .

Also, in order not to interfere with the view.setOnTouchListener((v, event) -> true); that are not used at the current time, I make them unTouch using view.setOnTouchListener((v, event) -> true);

But there is a problem. Sometimes another view , which is currently still unTouchable , intercepts events in oiInterceptTouchEvent() , but OnTouch not enter OnTouch .

Tell me what could be the problem. Can anyone come across?

Also during debugging, I saw that during the MotionEvent.ACTION_DOWN event in the dispatchTouchEvent(MotionEvent event) in the main view goes into the dispatchHoverEvent(MotionEvent event) and after that the second view intercepts the event, but it should not be so.

    1 answer 1

    I found the answer to this question, maybe someone else will face a similar problem. So, there is a very useful article on this topic.

    And in this order, the functions responsible for handling and sending events are called (if none of the View intercepted this event and returned false):

     Activity.dispatchTouchEvent -> EVENT-> Activity.onInterceptTouchEvent -> EVENT-> ViewGroup.dispatchTouchEvent -> EVENT-> ViewGroup.onInterceptTouchEvent -> EVENT-> View.onTouch -> EVENT-> ViewGroup.onTouch -> EVENT-> Activity.onTouch 

    Based on this, onTouch() is called after onInterceptTouchEvent() .