Receiving onTouch and onClick events with Android

后端 未结 7 1046
滥情空心
滥情空心 2020-12-16 04:02

I have a view that need to process onTouch gestures and onClick events. What is the proper way to achieve this?

I have an onTouchListener and

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-16 04:57

    isMove = false;
    case MotionEvent.ACTION_DOWN:
    //Your stuff
    isMove = false;
    case MotionEvent.ACTION_UP:
    if (!isMove || (Xdiff < 10 && Ydiff < 10 ) {
    view.performClick; //The check for Xdiff <10 && YDiff< 10 because sometime elements moves a little
    even when you just click it   
    }
    case MotionEvent.ACTION_MOVE:
    isMove = true;
    

    Another way is to use threads. That is on Action_Down start a thread to increment a counter. In case of Action_UP : stop/interrupt the thread. look for counter if it is less than 2 (say or threshold as per your application) or !isMove then invoke click function

提交回复
热议问题