2016-05-24 8 views
0

Ich habe eine Android App mit einem GridView.GestureDetector conflit onFling vs onSingleTapUp

In diesem Raster muss ich viele Ereignisse erkennen und ich muss einen GestureDetector verwenden, aber manchmal, wenn ich auf ein Rasterelement klicke, wird das Ereignis onFling statt onSingleTapUp ausgelöst.

Was mache ich falsch? Statt onSingleTapUp

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; 
     } 
} 

Meine Frage ist, unterscheidet sich von doppelten, weil ich, warum onFling die Android GestureDetector geht davon wissen wollen. Oder wenn ich etwas falsch mache.

+1

Mögliche Duplikat [Fling Gestenerkennung auf Raster-Layout] (http://stackoverflow.com/questions/937313/fling-gesture-detection-on-grid -Layout) –

Antwort

0

ich das Problem wie folgt gelöst:

@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;  
} 
Verwandte Themen