1

I have an android application. I have four screens and each screen contains a listview.. My requirement is that when a user flips horizontally then it should change the ui screen and when the user flips vertically it should scroll through the list.My code is

public boolean dispatchTouchEvent(MotionEvent event)
 {
     System.out.println("22");
       int eventaction=event.getAction();

         switch(eventaction) 
        {
          case (MotionEvent.ACTION_MOVE):
              System.out.println("move");
          a=1;
          break;

              case MotionEvent.ACTION_UP:
                  System.out.println("up");
              if(a==1)
              {
                  view1.setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_left));
                  view1.showNext();
              }
              a=0;
                  break;

          default:
          break;
        }

        return super.dispatchTouchEvent(event);
}
user1438128
  • 533
  • 2
  • 7
  • 12
  • @OlofEdler He is not having enough answers on their questions. May be because of he haven't asked question with full detail or may be due to require expertise or else. – Paresh Mayani Jun 17 '12 at 12:53
  • @Paresh. Then what about his comment: thanks a lot for the code....it is working absolutely http://stackoverflow.com/questions/11069250 Shound be marked as accepted, no? – r4. Jun 17 '12 at 12:55
  • @OlofEdler yes you are right. I just checked question list with no. of answers. – Paresh Mayani Jun 17 '12 at 12:58

1 Answers1

1

I had a similar issue where the children were eating up all the scroll events. I ended up overiding the onInterceptTouchEvent in the parent to detect if it was a horizontal or vertical swipe and acting accordingly. You would want something like this

@Override
public boolean onInterceptTouchEvent (MotionEvent ev){
    if(horizontalSwipe(ev)){
        return true;
    }
    else
        return false;

}

where you have some function that determines from your history if the new motion event constitutes a horizontal motion event.

MikeIsrael
  • 2,871
  • 2
  • 22
  • 34