0

Is there a way to trace the dispatching of a MotionEvent through the view hierarchy?

I have a case where I'm clearly tapping within the rectangle of a TextView (evident when I enable my device setting for: developer options - pointer location) but the TextView doesn't always consume the event.

Sometimes when I tap over the TextView, the event is consumed. Sometimes it apparently is not consumed because some other view receives it and acts on it (resulting in wrong behavior of my app).

I'm hoping to find a way to see if the TextView is, indeed, receiving the event. If not, then I probably have a bug in my code. If it is, then why is TextView not consuming it?

Anyone know how to trace which views see the event via onInterceptTouchEvent() or onTouchEvent()?

Thanks.

Brian
  • 7,955
  • 16
  • 66
  • 107
Peri Hartman
  • 19,314
  • 18
  • 55
  • 101
  • This is probably not the immediate solution, but are you returning `true` for you `onTouchEvent` in the `TextView` to indicate your consumed the event? – Brian Jul 18 '14 at 22:14
  • I'm using the stock TextView, thus I'm speaking of its stock behavior. – Peri Hartman Jul 18 '14 at 23:03
  • I did, in fact, subclass the TextView just so I could do my own "tracing". I seems that TextView never consumes MotionEvents unless, of course, editing is enabled. Not sure why I thought it was inconsistent. – Peri Hartman Jul 18 '14 at 23:07
  • What do you mean by when editing is enabled?... Anyway, in regards to your original question about tracking where `MotionEvent`s go, I don't know if there's a way follow a `MotionEvent` throughout its propagation in the view hierarchy. What are you trying to achieve? Perhaps there's a workaround? – Brian Jul 18 '14 at 23:17
  • editing enabled: EditView is a subclass of TextView with some settings changed and a little added functionality; I simply mean the cases where the widget is an EditView or its input method has been set to allow editing, or some other settings have been changed to allow editing. In such cases, it will most certainly consume touch events. – Peri Hartman Jul 19 '14 at 02:32

0 Answers0