Can't handle both click and touch events simultaneously

后端 未结 12 2056
时光说笑
时光说笑 2020-12-01 03:45

I am trying to handle touch events and click events on a button. I do the following:

button.setOnClickListener(clickListener);
button.setOnTouchListener(touc         


        
12条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-01 03:57

    In ACTION_UP perform onClick manually using condition

    boolean shouldClick = event.eventTime - event.downTime <= 200 // compares the time with some threshold
    

    So, try within MotionEvent.ACTION_UP

    if(event.eventTime - event.downTime <= 200) { // case or when statement of action Touch listener
        view.performClick();
    }
    

提交回复
热议问题