Android not detected inside fragment

I have a project based on a tab node and using fragments,

on one tab it has a Fragment list, the user selects a cell and goes to another fragment,

from there, the user can scroll between fragments of this tab,

The project works for me until I go to the cell in the Fragment list,

there I need to detect blows on the left or on the right to change fragments accordingly,

here is my code:

public class PrepareSkin extends Fragment implements OnGestureListener{

      private static final int SWIPE_MIN_DISTANCE = 120;
       private static final int SWIPE_MAX_OFF_PATH = 250;
       private static final int SWIPE_THRESHOLD_VELOCITY = 200;

       private GestureDetector gestureScanner;


    @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
       Bundle savedInstanceState) {


        gestureScanner = new GestureDetector(this);


      // TODO Auto-generated method stub
      View myFragmentView = inflater.inflate(R.layout.prepare_skin, container, false);

       Log.i("Mirko", "CREATO <<");


      return myFragmentView;
     }

       public boolean onTouchEvent(MotionEvent me)
       {
        return gestureScanner.onTouchEvent(me);
       }

    @Override
    public boolean onDown(MotionEvent e) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        try {
               if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
                   return false;
               // right to left swipe
               if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                   Log.i("Mirko", "LEFTERS <<");


               }  else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                   Log.i("Mirko", "rIGTHERS >>");

               }
               else if(e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
               }  else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
               }
           } catch (Exception e) {
               // nothing
           }

                   return true;
    }

    @Override
    public void onLongPress(MotionEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
            float distanceY) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onShowPress(MotionEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        // TODO Auto-generated method stub
        return false;
    }

}

so why doesn't my gesture recognizer work?

thank,

+5
source share
1 answer

This link seems like your mall: Android onCreateView snippet with gestures

OnGestureListener , clickListener Gesture Listener , .

, onDown() false - , true. , Android onUp(), onDown() true .

+1

All Articles