// TouchEvent1 Example // Source code file: MainActivity.java package it372.touchevent1; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; public class MainActivity extends AppCompatActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); View view = findViewById(R.id.view); view.setOnTouchListener(new View.OnTouchListener( ) { @Override public boolean onTouch(View v, MotionEvent e) { int x = (int) e.getX( ); int y = (int) e.getY( ); switch(e.getAction( )) { case MotionEvent.ACTION_DOWN: System.out.print("Touched Down: "); break; case MotionEvent.ACTION_MOVE: System.out.print("Moving: "); break; case MotionEvent.ACTION_UP: System.out.print("Touched Up: "); break; } System.out.println("x=" + x + " y=" + y); return true; } } }); } }