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??

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top