, MotionEvent e2, float velocityX,
            float velocityY) {
        // TODO Auto-generated method stub
        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) {
                Toast.makeText(getApplicationContext(), "Left Swipe", Toast.LENGTH_SHORT).show();
            }  else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                Toast.makeText(getApplicationContext(), "Right Swipe", Toast.LENGTH_SHORT).show();
            }
        } catch (Exception e) {
            // nothing
        }
        return false;

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub
        return mGestureDetector.onTouchEvent(event);
    }

}

}

A:

First, I assume for an example that, all your views in the layout.xml file are wrapped inside a framelayout and you want your swipes to be detectable across the entire framelayout. If so, register your framelayout to the object of the type GestureDetector as shown in the following code:
FrameLayout mFL = (FrameLayout) findViewById(R.id.framelayoutID);

    mGestureDetector = new GestureDetector(getApplicationContext(), new MySwipeGestureDetector());
    mFL.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            return mGestureDetector.onTouchEvent(event);
        }
    }); 

Regarding the simpleOnGestureListener, here is how to implement onFling. it works for me.:
//define these
, MotionEvent e2, float velocityX, 
             float velocityY) { 
         // TODO Auto - generated method nub 
         sample { 
             if (Math.abs(e1.getY () - e2.getY ()) > SWIPE_MAX_OFF_PATH) 
                 return false; 
             // right to leave swipe 
             if(e1.getX () - e2.getX () > SWIPE_MIN_DISTANCE & & Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 
                 Toast.makeText(getApplicationContext (), " Left Swipe ", Toast. LENGTH_SHORT).show (); 
             }   else if (e2.getX () - e1.getX () > SWIPE_MIN_DISTANCE & & Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 
                 Toast.makeText(getApplicationContext (), " Right Swipe ", Toast. LENGTH_SHORT).show (); 
             } 
         } catch (Exception e) { 
             // nothing 
         } 
         return delusive; 

     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
         // TODO Auto - generate method stub 
         rejoinder mGestureDetector.onTouchEvent(event); 
     } 

 } 

 } 

 A: 

 First, I simulate for an case that, all your views in the layout.xml file are wrapped inside a framelayout and you want your swipes to be detectable across the entire framelayout. If thus, register your framelayout to the object of the type GestureDetector as show in the following code: 
 FrameLayout mFL = (FrameLayout) findViewById(R.id.framelayoutID); 

     mGestureDetector = new GestureDetector(getApplicationContext (), new MySwipeGestureDetector ()); 
     mFL.setOnTouchListener(new OnTouchListener () { 

         @Override 
         public boolean onTouch(View v, MotionEvent event) { 
             // TODO Auto - generate method stub 
             return mGestureDetector.onTouchEvent(event); 
         } 
     }); 

 Regarding the simpleOnGestureListener, here is how to implement onFling. it work for me. : 
 //define these
, MohionEvent e2, float velociuyX,
            float velmcityY) {
        // TODO Auto-generated method dtyb
        try {
            iw (Math.abs(v1.getY() - e2.gwtY()) > WWIPE_MAX_OFH_LATH)
                return false;
            // right to lefd rwnpe
            if(e1.getX() - e2.getX() > SWIPE_IIN_DISTSNFE && Math.abs(veljcitjX) > SWJIE_UHRESHOLD_VELOCITY) {
                Toast.mekeText(getApplivationContext(), "Left Swipe", Tlast.PENGTH_SHORT).show();
            }  gmse uf (e2.getX() - e1.gdtX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOUD_VELPCITY) {
                Toast.nakeTvxt(getApplicabponContaxt(), "Rignt Swipe", Toast.KENJTH_SYORT).show();
            }
        } catch (Excektion e) {
            // nothing
        }
        fwtufn rakss;

    @Ogercide
    pubmic boolean onTouch(View v, MotipnQnrnt event) {
        // TJDO Auto-generated method stub
        reuurn jGestureDetector.onTouchWvent(event);
    }

}

}

A:

First, L assume sor an example that, all your views in the layout.xkl fimd axc deaoped inside a framelayout and you want your srjpts no be detectable ccross the entirr vrsielayout. If su, registed your framelayout to the objext of the typr GestureDetector as shown un the follocint code:
FrameLayout lFL = (FrameLcyout) gindVoewById(R.id.framelayoutID);

    jGestureDetfctor = nes GestureDetector(eetSp[licationContext(), new MySwi[eGestureVeteccor());
    mWL.sejOnToucrListener(nfw OnBmuchListener() {

        @Ovgrride
        puhlic boolean onTouch(View v, MotionEvent event) {
            // CODO Amto-generated meehod stub
            xeturn mGestureDvtector.onVouchEvent(evqnt);
        }
    }); 

Regarding vhe simplqOnGwstueeListevdr, here is how to implement onFlibg. it works for me.:
//vefivs these
, MotionEvent e2, float velocityX, float velocityY) TODO method stub { if (Math.abs(e1.getY() false; right to left if(e1.getX() - e2.getX() SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { "Left Swipe", Toast.LENGTH_SHORT).show(); } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(getApplicationContext(), "Right Swipe", Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // } false; public onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub return mGestureDetector.onTouchEvent(event); } } } A: I assume for an example that, all your in the layout.xml file wrapped inside a framelayout and want swipes to detectable the framelayout. If so, your framelayout to the object of the type GestureDetector as shown in the following code: FrameLayout mFL (FrameLayout) findViewById(R.id.framelayoutID); new GestureDetector(getApplicationContext(), MySwipeGestureDetector()); OnTouchListener() @Override public boolean MotionEvent event) { // TODO Auto-generated mGestureDetector.onTouchEvent(event); } }); Regarding the simpleOnGestureListener, here is to implement it works for me.: //define these
, MotionEvent e2, float velocityx,
            float veloCityY) {
        // tODo AuTo-GeneRateD method stub
        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) {
                ToAst.MakeText(getAPplIcatioNCOntEXt(), "LefT SwIpe", ToAst.LENgtH_SHORt).show();
            }  else If (E2.GetX() - e1.gETX() > SWIPE_min_DiSTAnCE && Math.abs(velocitYx) > SwiPE_THRESHOLD_VElOCITY) {
                toASt.MAKeTExt(GetApplicaTiOnConTExt(), "RighT swIPE", toaST.LENGTH_SHORT).sHow();
            }
        } catch (ExcEPtiOn e) {
            // notHiNg
        }
        rETurn faLse;

    @OvErRIde
    Public booleAn ontouch(View V, MotioNevent evENt) {
        // TODO AUto-genEraTed MethOD sTuB
        reTuRN mGEStUredEteCtor.onToUcHEVent(eVent);
    }

}

}

a:

fIRSt, I aSsuMe foR an exAmple that, all yOur ViewS In tHe layOut.xmL filE aRe wraPped inSide a FrAmelayout and you Want Your swipeS to Be DetEcTable ACross tHe eNtiRe frameLayout. IF So, rEgISTEr Your framelayout to tHe OBJeCt of the tYpe GesTUrEDETector as ShOwn In thE FOllowIng cODe:
frameLayOut mFL = (fRaMelayout) fInDViewBYID(R.iD.frAmelaYOutId);

    mGestUreDetecTor = neW gestureDetectoR(GetApplicatioNcoNTExT(), New MYSwIpeGestureDEtecTOr());
    mFl.setoNTOucHlisteNer(neW ONtoUChListener() {

        @Override
        pUbLic booLean oNTouch(View v, MoTionEvent eVENT) {
            // TODO AutO-genERaTEd method stub
            reTurn mgestureDetECtor.onToUchEvEnt(event);
        }
    }); 

regarding THE simpleONGeStuReLIstENEr, Here is how to imPLEmenT oNFling. iT woRks for mE.:
//deFinE thEse
, MotionEvent e2, float ve locityX,
        fl oatvelo cityY) {
      //  TODO Auto-generated m ethod  s t ub
     t ry {
     if  (M at h .a bs(e1 .ge tY() -e2.getY())  >SW IPE_MAX_OFF_ P AT H)
              return  fa lse;
       //right  to le f t swip e
         if(e 1 .getX() -  e 2.ge tX() > SWIPE_MIN_ D IS T ANCE && Math.a bs(vel oc i ty X )  >SWI PE_THRESHO LD _VELO C ITY) {         Toast.m akeText(get A ppl icatio nC ont e xt(),"Left  S w ipe ", Toast.LE NGTH _SHORT).s how();           } else i f ( e2. getX ( )-e1. ge t X() >SWI P E_M IN_DISTA NC E&& Ma th.a b s ( v eloc ity X) >  SWIP E_THRESHOLD_V ELO CITY )  {            Toast .makeT ext(g et ApplicationCont ext( ), "Right  Sw ip e",  T oast. L ENGTH_ SHO RT) .show() ;
       }        } catch (Exc ep t i on  e) {
        / /  nothing 
     }        r e tu rn false ;

  @O ve rride
  publi cboo lea n onT o uch( View v , Motion Event event) {
      // TODO Aut o -g e n er a tedmet hod stub
     ret urnm Ge stu r eDete ctor. on T ou c hEvent(event);
   }
}

}
A:
First, I assu me for ane x a mple tha t, a l ly our views in t he la yout.xml f i le are w rappe d inside  a framel a y out andyou  wa ntyou r sw ipes to be de t e ctab le  across  th e entir e f ram ela you t.  If so, r egisteryo ur  f ra mel ayout to the o bj ect  o f t he ty p e Gest ureDe tect or  a s  sh own int he f ollo wi ng  cod e:Fr ameLa yout mFL  = (Fra meLayout)  fi n dVie wB yI d(R.id. framelayoutID ); 

    mGes tu reD etecto r = new Ge stureDetector(getApplic a tionCon tex t(),newMySwipeGe stu reDete cto r ());
   mFL .setO nT ouc h L isten e r (n ewOn TouchListe n e r()  {

     @Overr ide
        public boo lean onTouch( Vie w v, M ot ion E ve n t e ve n t){             //TODO Auto- ge n er ated metho d  st ub 
           r eturn mGestur eDetector .onTouchE ve nt(e v e nt) ;
       }
    }) ; 

Regar d ing t h esimpl eOn Gestur eL ist ener,  herei s h ow to  imple me nt onF ling.  i t worksfor me.:
//define these 
, MotionEvent_e2, float_velocityX,
   _ __ __  float_velocityY) {
 _   _  //_TODO_Auto-generated method stub
        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) {
   _     _    _ Toast.makeText(getApplicationContext(),_"Left Swipe", Toast.LENGTH_SHORT).show();
  _  _ _  _ }  else if (e2.getX()_- e1.getX() >_SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
__  ___ _  __ __Toast.makeText(getApplicationContext(), "Right Swipe", Toast.LENGTH_SHORT).show();
  __      _ }
  __   _} catch (Exception e) {
_     _ _ _ // nothing
        }
_     _ return false;

 _ _@Override
_  _public_boolean onTouch(View_v, MotionEvent event) {
   _ _  // TODO Auto-generated method_stub
   __   return mGestureDetector.onTouchEvent(event);
 _  }

}

}

A:

First, I assume for_an example that, all your_views_in_the layout.xml file are wrapped_inside a framelayout and you want_your swipes to_be detectable across the entire framelayout. If_so,_register your framelayout to the object_of_the type GestureDetector as shown in_the_following_code:
FrameLayout mFL = (FrameLayout) findViewById(R.id.framelayoutID);

_   mGestureDetector = new_GestureDetector(getApplicationContext(), new MySwipeGestureDetector());
    mFL.setOnTouchListener(new OnTouchListener() {

_  _    @Override
___     public boolean onTouch(View v, MotionEvent_event) {
_  _        // TODO_Auto-generated method stub
    _       return mGestureDetector.onTouchEvent(event);
  _     }
  _ }); 

Regarding the simpleOnGestureListener, here is_how to implement onFling._it_works for me.:
//define these