Disable or prevent multitouch in Activity

前端 未结 9 1725
闹比i
闹比i 2020-11-30 03:11

I have several Views on an Activity which a user wants to touch quickly in succession and I capture these touches using a TouchListener and handling Motio

9条回答
  •  隐瞒了意图╮
    2020-11-30 03:43

    I got it to work for me by just adding some code in OnTouchEvent method,

    boolean action_down_required = false;
    
    @Override
    public boolean onTouchEvent(MotionEvent event) {
    
        int action = event.getAction();
    
        if(event.getPointerCount() > 1){
            action_down_required = true;
            return true;
        }
    
        if(action_down_required){
            action = MotionEvent.ACTION_DOWN;
        }
    
        switch (action) {
            case MotionEvent.ACTION_DOWN:
    
                // your code goes here...
    
                action_down_required = false;
                break;
    
            // Other events...
    

提交回复
热议问题