Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SimpleOnGestureListener not working for ScrollView

I have a screen where I have a header, a TextView inside a ScrollView and footer. I have to use ScrollView as the Text in the TextView can be long also.

Now when I am using SimpleOnGestureListener for this screen. It is not working for the ScrollView section. Removing the ScrollView everything working fine. But for the case of long text, some text are getting missed.

I want to use onFling and onDoubleTap in SimpleOnGestureListener.

Please advise.

Regards, Shankar

like image 632
Bhabani Shankar Avatar asked Aug 21 '11 10:08

Bhabani Shankar


2 Answers

I got the solution for this issu

Add following method in the your Activity class

@Override
public boolean dispatchTouchEvent(MotionEvent ev){
    super.dispatchTouchEvent(ev);
    return gestureScanner.onTouchEvent(ev);
} 

As suggested in the below link:

http://groups.google.com/group/android-developers/browse_thread/thread/9fdfb03d0959e299

like image 170
Bhabani Shankar Avatar answered Nov 12 '22 05:11

Bhabani Shankar


You have to create a custom ScrollView object and override it's onTouchEvents to also check for your gestures. It's demonstrated in the following code.

public class GestureScrollView extends ScrollView {
    GestureDetector myGesture;

    public GestureScrollView(Context context, GestureDetector gest) {
        super(context);
        myGesture = gest;
    }

    public GestureScrollView(Context context) {
        super(context);
    }

    public GestureScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (myGesture.onTouchEvent(ev))
            return true;
        else
            return super.onTouchEvent(ev);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (myGesture.onTouchEvent(ev))
            return true;
        else
            return super.onInterceptTouchEvent(ev);
        }
    }

Let me know if you run into any issues. :)

-Zaid

like image 23
Zaid Daghestani Avatar answered Nov 12 '22 04:11

Zaid Daghestani