Find out which View consumed touch event, if any
Asked Answered
E

1

7

I was troubleshooting a view-related issue: a click listener that is not fired when it's supposed to. After a long session of trial-and-error, I found out that a parent view was disabled, thus discarding all events to its children.

Is there a way, in Android, to find exactly what happens to a touch or click event when it is injected to the app? Like how was it dispatched, which views were traversed by it, who ignored it (and why), who discarded it (and why) and finally who consumed it.

Ideally it would be some kind of low-level dump on Logcat emitted for every click in the app.

Eucken answered 4/4, 2017 at 15:27 Comment(1)
You can find views which under finger touch point,then override onTouchEvent() method and set breakpoints to them to see if there is a view have handled events instead of your expected view.(This is a ugly way...)Fishgig
G
2

As you can see in the similar post at the issue tracker Dianne Hackborn writes:

There currently isn't a way to do this.

Meaning, there is no such an API in the framework.

But you can have a custom root ViewGroup and listen for each and every touch event (via onInterceptTouchEvent()) and dump the MotionEvent.

I believe that's the only possible way so far.

Gunk answered 4/4, 2017 at 15:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.