Search code examples
androideventsinputtouch

How do I detect touch input on the Android


Right now all I am trying to do is detect when the screen is pressed and then display a log message to confirm it happened. My code so far is modified off of the CameraPreview sample code (it will eventually take a picture) so the bulk of the code is in a class that extends SurfaceView. API for the example code from the SDK is 7.


Solution

  • Try code below to detect touch events.

    mView.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            //show dialog here
            return false;
        }
    });
    

    To show dialog use Activity method showDialog(int). You have to implement onCreateDialog(). See documentation for details.