我有一个配置了手势监听器的布局OnTouchEvent()
。布局包含一个列表视图,我正在使用手势来捕获列表视图的行 ID。我有以下代码 -
itemsList.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent evt) {
// TODO Auto-generated method stub
//
int action = evt.getAction();
final String DEBUG_TAG = "DEBUG";
detector.onTouchEvent(evt);
switch(action) {
case (MotionEvent.ACTION_DOWN) :
Log.d(DEBUG_TAG,"Action was DOWN");
return true;
case (MotionEvent.ACTION_MOVE) :
Log.d(DEBUG_TAG,"Action was MOVE");
return true;
case (MotionEvent.ACTION_UP) :
Log.d(DEBUG_TAG,"Action was UP");
return true;
case (MotionEvent.ACTION_CANCEL) :
Log.d(DEBUG_TAG,"Action was CANCEL");
return true;
case (MotionEvent.ACTION_OUTSIDE) :
Log.d(DEBUG_TAG,"Movement occurred outside bounds " +
"of current screen element");
return true;
}
return false;
}
});
检测器是 GestureDetector 实例。我基本上只是在列表视图的一行上使用向左滑动或向右滑动动作。
每当我向左/向右滑动时,我都会在 Logcat 中收到 3 条调试消息(信息或要查看的东西??)。
D/InputEventConsistencyVerifier(24700): TouchEvent: ACTION_MOVE contained 1 pointers
but there are currently 0 pointers down.
D/InputEventConsistencyVerifier(24700): in android.view.GestureDetector@b50cf9b0
D/InputEventConsistencyVerifier(23596): 0: sent at 37751425150760,
MotionEvent { action=ACTION_MOVE, id[0]=0, x[0]=39.00721, y[0]=28.526703, toolType[0]=TOOL_TYPE_FINGER,
buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=37751425,
downTime=37751133, deviceId=0, source=0x1002 }
还有来自 OnTouchListener 的 4 条调试消息 -
Action was ACTION MOVE
Action was ACTION MOVE
Action was ACTION MOVE
Action was ACTION UP
这对应于我相信的滑动动作。
因此,主要活动类扩展OnGestureListener
了其未实现的方法,例如 onFling.. 等。
问题是仅在ACTION UP
事件之后调用 onFling 方法,并且当发生这种情况时,传递给方法 mevt1 的参数为空,而 mevt2 不为空。(默认行为?)
onFling(MotionEvent mevt1,MotionEvent mevt2,浮动 velX,浮动 velY)
该方法使用 mevt1,因此会导致 nullpointexception。
我想知道来自的调试消息InputEventConsistencyVerifier
是否有任何问题,是否有人知道这是否有任何问题?