android - OnClick ImageView with OnFling ViewFlipper -


i have viewflipper holds single imageview. want able swipe change image / view, , click image play sound.

i have gesturedetector handling onfling change view. tried put onclicklistener imageview, worked stopped onfling working.

lastly, added onsingletapconfirmed gesturedetector. worked, registers click anywhere in activity not imageview.

can suggest how narrow down onsingletapconfirmed work on imageview?

here's code far:

 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) {                 log.v("swipe", "right left");                  viewflipper.setinanimation(slideleftin);                 viewflipper.setoutanimation(slideleftout);                 viewflipper.addview(nextimage(true));                  viewflipper.shownext();              }  else if (e2.getx() - e1.getx() > swipe_min_distance && math.abs(velocityx) > swipe_threshold_velocity) {                 log.v("swipe", "left right");                  viewflipper.setinanimation(sliderightin);                 viewflipper.setoutanimation(sliderightout);                 viewflipper.addview(nextimage(false));                 viewflipper.shownext();             }         } catch (exception e) {             // nothing         }         return false;     }      @override     public boolean onsingletapconfirmed(motionevent e)     {         // todo auto-generated method stub          log.v("singletap", "onsingletapconfirmed run");          return super.onsingletapconfirmed(e);         }      }  private view nextimage(boolean righttoleft) {     imageview imgv1 = new imageview(this);      if(righttoleft == true)     {              uri image = uri.parse("android.resource://com.owentech.brainybaby/drawable/" + variables.letters[variables.currentpos]);             imgv1.setimageuri(image);             imgv1.setscaletype(imageview.scaletype.center_inside);      return imgv1; } 

i had encountered problem in past.

maybe can try implement single tap setting ontouchlistener viewflipper, thus, viewflipper touch event receiver. write playing sound code in ontouch function. finally, set ontouch function's return value false sake of keeping onfling working.

viewflipper.setontouchlistener(new ontouchlistener() {       @override       public boolean ontouch(view view, motionevent e) {           // todo auto-generated method stub           switch(e.getactionmasked())           {              case motionevent.action_down:                   //put playing sound code here.                   break;           }           return false;  //means listener dosen't consume event       } } ); 

it's simple solution solve problem. if want achieve more complicated function such avoiding sound playing when finger swiping on screen change view, have take more effort distinguish gestures, e.g. calculate time between action_down event , action_up event , play sound if it's less 300ms.

i hope helpful you. :)


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -