2016-05-24 6 views
0

私はGridViewを持つAndroidアプリを持っています。GestureDetector conflit onFlingとonSingleTapUp

多くのイベントを検出する必要があり、GestureDetectorを使用する必要がありますが、グリッドアイテムをクリックすると、onSingleTapUpの代わりにイベントonFlingがトリガーされることがあります。

私は間違っていますか?

class GestureDetectorGrid extends SimpleOnGestureListener 
{ 
     /** 
     * Sliding from right to the left to move to another grid 
     */ 
     @Override 
     public boolean onFling(MotionEvent e1, MotionEvent e2, 
           float velocityX,float velocityY) 
     { 
      //my code 
      return false;  
     } 

     /** 
     * Go to another Activity by clicking on a element from the grid. 
     */ 
     @Override 
     public boolean onSingleTapUp(MotionEvent e) 
     { 
      //my code 
      return true; 
     } 

     @Override 
     public void onLongPress(MotionEvent e) 
     { 
      //my code 
      super.onLongPress(e); 
     } 

     @Override 
     public boolean onScroll(MotionEvent e1, MotionEvent e2, 
           float distanceX, float distanceY) 
     { 
      //my code 
      return true; 
     } 

     @Override 
     public void onShowPress(MotionEvent e) 
     { 
      super.onShowPress(e); 
     } 

     @Override 
     public boolean onDown(MotionEvent e) 
     { 
      //my code 
      return true; 
     } 
} 

私はAndroidのGestureDetectorがonFling代わりonSingleTapUpを前提として理由を知りたいので、私の質問は、重複は異なっています。それとも私が何か悪いことをしている場合。

+1

[グリッドレイアウト上の情事のジェスチャ検出]の可能な重複(http://stackoverflow.com/questions/937313/fling-gesture-detection-on-gridを-レイアウト) –

答えて

0

私はこのような問題解決:

@Override 
public boolean onFling(MotionEvent e1, MotionEvent e2, 
         float velocityX,float velocityY) { 

    int posIni = pointToPosition((int) e1.getX(), (int) e1.getY()); 

    int posFin = pointToPosition((int) e2.getX(), (int) e2.getY()); 

    if(posIni == posFin) { 
     //onClick code 
    } 
    else { 
     //onFling code. 
    } 
    return true;  
} 
関連する問題