Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it able to trigger a `MotionEvent.ACTION_DOWN` event programmatically on android?

Tags:

android

events

Here is some simple android code:

@Override
public boolean onTouch(View v, MotionEvent event) {
    int action = event.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            // do something
            break;
        case MotionEvent.ACTION_MOVE:
            // do something
            // how to trigger a ACTION_DOWN event here?
            break;
}

I want to trigger a ACTION_DOWN event when I handle ACTION_MOVE. Is it possible?

like image 894
Freewind Avatar asked Oct 19 '25 11:10

Freewind


1 Answers

You can try like this.

@Override
public boolean onTouch(View v, MotionEvent event) {
    int action = event.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            // do something
            break;
        case MotionEvent.ACTION_MOVE:
            // do something
            // how to trigger a ACTION_DOWN event here?
            event.setAction(MotionEvent.ACTION_DOWN);
            onTouch(v,event);
            break;
             }
}
like image 163
Rasel Avatar answered Oct 21 '25 00:10

Rasel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!