Difference between Click and Touch Listeners in Android

后端 未结 4 598
暗喜
暗喜 2021-02-07 03:11

I have a bit of doubt. I am using an image button (e.g. Play icon in media player). I want to know which action Listener I am supposed to use, onClickListener or onTouchListener

4条回答
  •  忘了有多久
    2021-02-07 03:58

    • onClickListener is used whenever a click event for any view is raised, say for example: click event for Button, ImageButton.

    • onTouchListener is used whenever you want to implement Touch kind of functionality, say for example if you want to get co-ordinates of screen where you touch exactly.

    Update:

    Just check the official doc for both: onClickListener and onTouchListener.

    So from official doc, definition for both are:

    • onClickListner: Interface definition for a callback to be invoked when a view is clicked.
    • onTouchListener: Interface definition for a callback to be invoked when a touch event is dispatched to this view. The callback will be invoked before the touch event is given to the view.

提交回复
热议问题