0

:) I'm trying to separate the touch from the slide but I can't get it right: - when the user slides the screen I want to get only slides

                public void onTouchEvent(MotionEvent event) {
                    if (event.getAction() == MotionEvent.ACTION_MOVE ) {                        
                        Log.e(Logcat, "1 slide");              
                    }
                    else
                    if (event.getAction() == MotionEvent.ACTION_DOWN) {                         
                        Log.e(Logcat, "1 touch");              
                    }           

                    super.onTouchEvent(event);                      
            }   

Thank you!


edit

                public void onTouchEvent(MotionEvent event) {
                    if (event.getAction() == MotionEvent.ACTION_MOVE ) {
                        slide = true;
                        Log.e(Logcat, "1 slide");              
                    }
                    else
                    if (event.getAction() == MotionEvent.ACTION_DOWN) {
                        slide = false;             
                    }           
                    else if (event.getAction() == MotionEvent.ACTION_UP)
                    {
                        if(!slide)
                        {
                        touch =1;
                        Log.e(Logcat, "1 touch");
                        }
                    }

                    super.onTouchEvent(event);                      
            }

This doesn't work neither, all i get is a number of slides (even on touch)

Misca
  • 459
  • 2
  • 11
  • 31

1 Answers1

1

Some pseudo code:

boolean sliding = false;

ontouch() {

  if(move){
     //might do some time/distance checks for these to run
     sliding = true;
     doSlideActions();
  }else if(down){
     sliding = false;
  }else if(up){
     if(!sliding) doDownAction();
  }
}
Will Kru
  • 5,164
  • 3
  • 28
  • 41
  • Hi Misca, that's why you should check for a certain swipe distance or time frame in order for slide to be true. On a second thought you could just leave the slide variable but store the touch position on down, then on up check the current position against the down position. If the distance between them exceeds a certain value, you have a slide, else you have a touch. – Will Kru Apr 02 '11 at 00:48