1. Check out our app, Forums for Android! Download and leave feedback here!

Problem with ViewFlipper and TouchEvent

Discussion in 'Application Development' started by eafkuor, Mar 19, 2010.

  1. eafkuor

    eafkuor Member
    Thread Starter
    5

    Mar 19, 2010
    7
    0
    5
    Hi everyone, in my app there's a ViewFlipper that shows 3 different layouts, and the user can switch between them (the new one comes in from the left, the old one goes out to the right, and vice versa) by using two Buttons.
    I wanted to give the user a chance to simply press the screen, move the finger, and release it, to switch between the same layouts.
    So I attached the ViewFlipper to this onTouchListener:

    Code (Text):
    1. public boolean onTouch(View v, MotionEvent event) {
    2.        
    3.         float startx=0, endx=0;
    4.         ViewFlipper flipper=(ViewFlipper)v;
    5.  
    6.        
    7.         switch(event.getAction()){
    8.             case MotionEvent.ACTION_DOWN:
    9.                 startx=event.getRawX();
    10.                 break;
    11.                
    12.             case MotionEvent.ACTION_MOVE:
    13.                 break;
    14.                
    15.             case MotionEvent.ACTION_UP:
    16.                 endx=event.getRawX();
    17.                 if(endx-startx > 50){
    18.                     //move to the left
    19.                     flipper.setInAnimation(Animations.inFromLeftAnimation());
    20.                     flipper.setOutAnimation(Animations.outToRightAnimation());
    21.                     flipper.showPrevious();
    22.                 }
    23.                 else if(startx-endx > 50){
    24.                     //move to the right
    25.                     flipper.setInAnimation(Animations.inFromRightAnimation());
    26.                     flipper.setOutAnimation(Animations.outToLeftAnimation());
    27.                     flipper.showNext();
    28.                 }
    29.                 break;
    30.         }
    If I call the same methods on flipper in the Buttons' onClick() callback, the animation works fine.
    But in this, it doesn't work right, it always moves to the left. And it also moves if you just click on the screen without moving the finger (it should move only if you moved the finger more than 50 pixels).
    Do you have an idea why?
    Thanks!
    Simone
     

    Advertisement

Share This Page

Loading...