android - MyGestureDetector extends SimpleOnGestureListener -


i implementing mygesturedetector extends simpleongesturelistener. borrowed class from: http://www.codeshogun.com/blog/tag/view-flipper/ allow swipe action in viewflipper. can not if function on emulator. suggestions?

below of code:

the main.java

import android.app.activity; import android.os.bundle; import android.view.gesturedetector; import android.view.keyevent; import android.view.motionevent;import android.view.view; import android.view.gesturedetector.simpleongesturelistener; import android.view.animation.animation; import android.view.animation.animationutils; import android.webkit.webview; import android.widget.viewflipper;   public class main extends activity {  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 gesturedetector; view.ontouchlistener gesturelistener; private animation slideleftin; private animation slideleftout; private animation sliderightin; private animation sliderightout; private viewflipper viewflipper;      @override     public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);      // ---------------------------------sets swipe animation next view -->            viewflipper = (viewflipper)findviewbyid(r.id.ac4313);     slideleftin = animationutils.loadanimation(this, r.anim.slide_left_in);     slideleftout = animationutils.loadanimation(this, r.anim.slide_left_out);     sliderightin = animationutils.loadanimation(this, r.anim.slide_right_in);     sliderightout = animationutils.loadanimation(this, r.anim.slide_right_out);      gesturedetector = new gesturedetector(new mygesturedetector());     gesturelistener = new view.ontouchlistener() {         public boolean ontouch(view v, motionevent event) {             if (gesturedetector.ontouchevent(event)) {                 return true;             }             return false;         }     };      }  class mygesturedetector extends simpleongesturelistener {     @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 left swipe             if(e1.getx() - e2.getx() > swipe_min_distance && math.abs(velocityx) > swipe_threshold_velocity) {                 viewflipper.setinanimation(slideleftin);                 viewflipper.setoutanimation(slideleftout);                 viewflipper.shownext();             }  else if (e2.getx() - e1.getx() > swipe_min_distance && math.abs(velocityx) > swipe_threshold_velocity) {                 viewflipper.setinanimation(sliderightin);                 viewflipper.setoutanimation(sliderightout);                 viewflipper.showprevious();             }         } catch (exception e) {             // nothing         }         return false;     } }      @override // ------------------------------ catch gesture event overriding ontouch() method: --> public boolean ontouchevent(motionevent event) {     if (gesturedetector.ontouchevent(event))         return true;     else         return false; }  

the anim *.xml's:

<?xml version="1.0" encoding="utf-8"?>  <set xmlns:android="http://schemas.android.com/apk/res/android">     <translate android:fromxdelta="100%p" android:toxdelta="0" android:duration="800"/> </set>  

i think problem don't override ondown event. add code snippet mygesturedetector class, , should work.

@override public boolean ondown(motionevent e) {     return true;         } 

the ondown event return false default, , every gesture start ondown onfling event not fire.

istvan


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -