我有一个配置了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;
}
});
detector是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 ..等等。
问题是onFling方法仅在ACTION UP
事件之后被调用,当发生这种情况时,传递给方法mevt1的参数为null,而mevt2不为null。 (默认行为?)
onFling(MotionEvent mevt1,MotionEvent mevt2,float velX,float velY)
该方法使用mevt1,因此会导致nullpointexception。
我想知道来自InputEventConsistencyVerifier
的调试消息是否有任何问题,是否有人知道这是否有任何问题?
答案 0 :(得分:0)
你必须致电
detector.onTouchEvent(evt)
每个动作,而不仅仅是ACTION_MOVE