I have some code that I wrote to implement a vertical swipe on a Gallery widget. It works great in Android 1.5 and 1.6 but does not work in Android 2.2 (I have yet to try it with 2.1).
public class SwipeUpDetector extends SimpleOnGestureListener implements OnTouchListener { private GestureDetector m_detector; public SwipeUpDetector() { m_detector = new GestureDetector(m_context, this); } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (Math.abs(e1.getX() - e2.getX()) < s_swipeMaxOffPath && e1.getY() - e2.getY() >= s_swipeMinDistance && Math.abs(velocityY) >= s_swipeMinVelocity) { int pos = m_gallery.pointToPosition((int)e1.getX(), (int)e2.getY()); startAnimation(pos); return true; } return false; } @Override public boolean onTouch(View v, MotionEvent event) { return m_detector == null ? false : m_detector.onTouchEvent(event); } } And to be able to get my gallery to detect the onFling I have the following: m_gallery.setOnTouchListener(new SwipeUpDetector()); In Android 1.5 and 1.6 this works great. In Android 2.2 onFling() is never called. In looking around on Google and StackOverflow I found one possible solution was to implement onDown() and return true. However, I am also listening to single clicks and have a context menu listener set up on this gallery. When I implement onDown() and return true I do indeed get the swipe to work. But when I do this the context menu doesn't display on a long click and the single clicks don't work either... Clicking on items in the gallery cause the gallery to jump around and I don't get any feedback when I click on an item in the gallery. It just immediately makes that item the selected item and moves it to the center. I looked at the API differences report between 1.6, 2.1, and 2.2 and didn't see anthing of significance that could have caused this to break... What am I doing wrong? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en