How to get a continuous Touch Event?

后端 未结 7 1585
死守一世寂寞
死守一世寂寞 2021-01-17 14:01

My class extends View and I need to get continuous touch events on it.

If I use:

public boolean onTouchEvent(MotionEvent me) {

    if(me.getAction()         


        
7条回答
  •  悲&欢浪女
    2021-01-17 14:17

    All these answer are partially correct but they do not resolve in the right way the problem.

    First of all, for everyone out there that decide to track when the event is ACTION_MOVE. Well that works only guess when? When user move his finger, so could if you decide to implement a custom thumb control is okay but for a normal custom button that's not the case.

    Second, using a flag inside ACTION_DOWN and check it in ACTION_UP seems the logic way to do it, but as Clusterfux find out if you implement a while(!up_flag) logic you get stuck into troubles ;)

    So the proper way to do it is mentioned here:

    Continuous "Action_DOWN" in Android

    Just keep in mind that if the logic you're going to write during the continuous press has to modify the UI in some way, you have to do it from the main thread in all the other cases it's better use another thread.

提交回复
热议问题