Android listener for screen tap detection

I have a view in an Android application that needs to be constantly updated when the screen is clicked. Most of the listeners I discovered are invalid only once when the user first touches the screen, or when the user removes his hand from the screen.

Is there such a thing as a listener that is constantly triggered while the screen is touched? Or is there any other way to do this? I know it sounds very simple somehow, but I did not find a way to do it.

+5
source share
1 answer

Replace onTouch()and set the flag to ACTION_DOWN. Until ACTION_UPit is called after that, the user touches the screen.

boolean pressed = false;

@Override
    public boolean onTouch(View v, MotionEvent event) {

        //int action = event.getAction();
        switch (event.getAction()){
        case MotionEvent.ACTION_DOWN:
            pressed = true;
        break;

        case MotionEvent.ACTION_MOVE:
            //User is moving around on the screen
        break;

        case MotionEvent.ACTION_UP:
            pressed = false;
        break;
        }
        return pressed;
    }
+8
source

All Articles