Question

I have a TextView in a fragment where I want to set different texts when the gesture is detected.

@Override
public boolean onTouchEvent(MotionEvent event) {
    this.gestureDetector.onTouchEvent(event);
    return super.onTouchEvent(event);
}

The above code is used to listen for gesture, but it can only be used in an Activity class somehow, when I put .onTouchEvent() in a fragment class, it says cannot resolve method. Any idea how I can manipulate a view from outside the fragment or any ways to basically listen for the gestures like I did in the Activity class??

Was it helpful?

Solution

You can add touch listeners to views, so get the root view of that fragment, and add your listener with view.setOnTouchListener(...)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top