27.7 Implementing the Touch Event Listener
In order to receive touch event notifications it will be necessary to register a touch listener on the layout view within the onCreate() method of the MainActivity activity class. Select the MainActivity.java tab from the Android Studio editor panel to display the source code. Within the onCreate() method, add code to identify the ConstraintLayout view object, register the touch listener and implement code which, in this case, is going to call a second method named handleTouch() to which is passed the MotionEvent object:
package com.ebookfrenzy.motionevent;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import androidx.constraintlayout.widget.ConstraintLayout;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
...