是否能够在android上以编程方式触发`MotionEvent.ACTION_DOWN`事件?

时间:2012-11-23 11:58:45

标签: android events

这是一些简单的Android代码:

@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;
}

我想在处理ACTION_DOWN时触发ACTION_MOVE事件。有可能吗?

1 个答案:

答案 0 :(得分:7)

你可以这样试试。

@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;
             }
}