If you make a mistake tap, drag it out of range and then cancel it (I want to disable the touch event)

Asked 2 years ago, Updated 2 years ago, 43 views

If you accidentally tap and want to drag and release and cancel
How do I go through a touch event?
Normally, I only need to use ClickListener, but I also want to implement touch events

In the case below, even if it's out of range, it's still processing 123
Normally, I only want to do one or two actions, but only when I cancel
(Action_MOVE is included in this program.)

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

    switch(event.getAction()) {
        caseMotionEvent.ACTION_DOWN:
            // Processing.1
            break;
        caseMotionEvent.ACTION_UP:
            // Processing.2
            break;
    }
    return false;
}

@ Override
public void onClick (View view) {
    // Processing.3
}

If the switch statement in the touch event is largely bound by the if statement and false, do not switch it.
I think I can do it, but how are you doing?
Also, is there a way not to implement ClickListener?

Thank you for your cooperation

android java

2022-09-30 19:47

1 Answers

If I were you, I would only use onTouch, and I would branch the inside of processing 2 with if.

Use event.getX(), event.getY() in process 1 and process 2 to obtain the position when tapped and separated.Then, in Action 2, compare the valid range of the tap (which is calculated in advance) and perform Action 2 if it is valid and Action 3 if it is out of range.


2022-09-30 19:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.