Home > Mobile > How to monitor a particular view sliding event?
How to monitor a particular view sliding event?
Time:01-26
I look at the official documentation is written, so if I want to monitor a particular view, how should change?
Public class MainActivity extends the Activity {
Private GestureDetectorCompat mDetector;
@ Override Public void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); The setContentView (R.l ayout. Activity_main); MDetector=new GestureDetectorCompat (this, new MyGestureListener ()); }
@ Override Public Boolean onTouchEvent (MotionEvent event) { //here, for example, I want to listen textView1, should how to write This. MDetector. OnTouchEvent (event); Return super. OnTouchEvent (event); }
The class MyGestureListener extends GestureDetector. SimpleOnGestureListener { Private static final String DEBUG_TAG="Gestures";
@ Override Public Boolean onDown (MotionEvent event) { The d (DEBUG_TAG, "onDown:" + event. The toString ()); return true; }
@ Override Public Boolean onFling (MotionEvent event1, MotionEvent event2, {float velocityX, float velocityY) The d (DEBUG_TAG, "onFling:" + event1. ToString () + event2. ToString ()); return true; } } }
CodePudding user response:
To want to listen to the view to register this onTouchEvent event, tend to have similar setOnTouch... The Listener, code written to rewrite the anonymous interface implementation in the interface.
CodePudding user response:
GestureDetectorCompat is to monitor your finger in the current screen click or sliding, so why do you want to monitor textView1?