Domanda

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

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top