EditText only calling ACTION_DOWN and ACTION_CANCE

2019-07-09 06:47发布

问题:

I have a class which is extending EditText, and when I tap on my control sometimes the only events I get dispatched to the control are ACTION_DOWN and ACTION_CANCEL. This causes the soft keyboard to not come up. What I expect, and occurs the other half of the time, is for the ACTION_DOWN, ACTION_UP, and ACTION_CANCEL events to fire.

I have done some research and from previous SO posts, and these two common problems that are similar to this are not true:

  1. My onTouchEvent method does not return false. It always returns true (calling super.onTouchEvent(ev);).
  2. There are no other control that are intercepting my touch event. I've put break points on the other classes I have which implement onInterceptTouchEvent(), and none of them hit. Also, I cannot find any other class where an onTouchEvent is broken while debugging.
  3. I've put overridden dispatchTouchEvent in all of my classes which are in the call stack for the working case where a ACTION_UP event is dispatched. However, in the case where the ACTION_UP event is not dispatched, none of the spots in the call stack get hit. This leads me to believe that the ACTION_UP event was never queued up? I don't know how this can be possible.

I've tried to debug source, and I am able to break inside the EditText onTouchEvent. This is how I was able to narrow down that my problem is the ACTION_UP event is not firing. What I would like to do is also break on the ViewGroup's dispatchTouchEvent method to debug that further, but I am unable to put a break point in there.

My questions are:

  1. Does anyone what could cause an event dispatch of ACTION_DOWN -> ACTION_CANCEL without a ACTION_UP in the middle? Other than returning false on the onTouchEvent handle or intercepting the touch events.
  2. Is there a way to debug the ViewGroup dispatching so I might be able to further triage what state is causing the UP event to not dispatch. I'm really hopeful that the Android framework does have the UP event somewhere and something's state is making it get lost.