Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out which View consumed touch event, if any

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.

like image 398
ris8_allo_zen0 Avatar asked Oct 29 '22 09:10

ris8_allo_zen0


1 Answers

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.

like image 136
azizbekian Avatar answered Nov 15 '22 05:11

azizbekian