How to detect onLongClick ACTION_UP event?

前端 未结 1 1925
北荒
北荒 2020-12-20 08:47

I have an image which implements both OnClickListener and OnLongClickListener. In the OnLongClickListener at press down (ACTION_

相关标签:
1条回答
  • 2020-12-20 09:16

    Just use OnTouchListener and forget about OnLongClickListener. You can detect a long click by checking coordinates and pressed time, you have all that info in MotionEvent object passed by OnTouch().

    1- To check coordinates, use getX() and getY() from MotionEvent and getDrawingRect() from your ImageView container.

    2- To check for pressed time, use getEventTime(), storing first time in ACTION_DOWN and then compute by substracting with time in ACTION_UP event. You could assume like 800mS for a long click.

    0 讨论(0)
提交回复
热议问题