Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect touch input on the Android

Tags:

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.

like image 209
RyoxSinfar Avatar asked Jun 29 '10 16:06

RyoxSinfar


People also ask

Which method you should override to control your touch action android?

To make sure that each view correctly receives the touch events intended for it, override the onInterceptTouchEvent() method. Refer to the following related resources: Input Events API Guide. Sensors Overview.

How do you implement touch events?

Add the touch point handlers to the specific target element (rather than the entire document or nodes higher up in the document tree). Add touchmove , touchend and touchcancel event handlers within the touchstart . The target touch element or node should be large enough to accommodate a finger touch.

Which method you should override to control your touch action?

To make sure that each view correctly receives the touch events intended for it, override the onInterceptTouchEvent() method.


1 Answers

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.

like image 161
Dariusz Bacinski Avatar answered Sep 22 '22 20:09

Dariusz Bacinski