2013-04-25 76 views
0

我有一个配置为OnTouchEvent()的手势监听器的布局。该布局包含一个列表视图,我正在使用手势来捕获列表视图的行ID。 我有以下代码 -Android OnTouchEvent:调试InputEventConsistencyVerifier消息

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 [email protected] 

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,浮velX,浮法velY)

该方法使用mevt1,因此这将导致nullpointexception。

我想知道InputEventConsistencyVerifier的调试信息是否有问题,如果有人知道这是否有问题?

回答

0

你必须调用

detector.onTouchEvent(evt) 

的每一个动作,不只是ACTION_MOVE

+0

对不起,前面的代码我粘贴是从我的调试会话。新代码已更新。我运行此代码时,我的应用程序崩溃。我发现如果我也使用onScroll(),结果是一样的。即应用程序崩溃。 – sangameshk 2013-04-25 10:17:44

+0

为什么你总是回归真实?返回探测器的值 – pskink 2013-04-25 10:50:21

+0

我不知道如何,但我写了一些触摸事件代码从头开始到基础知识,我不再得到错误,一切正常。我相信这个错误可能是由于父视图或子视图中触摸事件的处理不当(Listview上下文)造成的。 – sangameshk 2013-04-27 11:42:10