0

Basically, I have a ViewFlipper that flips when I swipe my finger on it. This is the code I have in my Activity:

public boolean onTouchEvent(MotionEvent touchevent) {
    switch (touchevent.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        oldTouchValue = touchevent.getX();
        break;
    }
    case MotionEvent.ACTION_UP: {
        float currentX = touchevent.getX();
        if (oldTouchValue > currentX) {
            ViewHelper.swapFlipperNext(vf);//helper method for flipping
            setMyProgress();//helper method to set my progress bar
        }
        if (oldTouchValue < currentX) {
            ViewHelper.swapFlipperPrevious(vf);
            setMyProgress();
        }
        break;
    }
    }
    return false;
}

It works perfectly except for one thing, I can flip it if my finger is on a non-view part of the screen. But if my figure swipe on some views(Since I have textviews and webviews in each page of the flipper too), the onTouchEvent doesn't get activated, so the ViewFlipper doesn't get switched, how do I fix that? Thanks a lot

user685275
  • 2,097
  • 8
  • 26
  • 32

1 Answers1

0

try setting the focusable attribute on your textviews and webviews to false. basically what i think is happening is these are consuming the touch event.

EDIT: if this doesn't work, try the following

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (gestureDetector != null) {
        gestureDetector.onTouchEvent(ev);
    }
    return super.dispatchTouchEvent(ev);
}

where gestureDetector is a member variable.

see from here: EditText not capturing ViewFlipper flings?

Community
  • 1
  • 1
jkhouw1
  • 7,320
  • 3
  • 32
  • 24
  • I think it may because of that too, but the problem is, I have tried to set those view's focusable to false, but they became not editable, I still need to do operations on those, besides, it still can't switch, even if I set those – user685275 May 21 '11 at 02:08
  • Problem solved, but my flipper flips even if I drag to view my webview and other stuff in it-_- – user685275 May 21 '11 at 05:05