Difference between OnTouch and OnClick Android

Is there a difference between OnTouchListener and OnClickListener ? I do not ask in terms of programming, but in terms of User Experience.

Which one is better to use?

Do I need to implement both?

+68
android
03 Feb 2018-12-12T00:
source share
6 answers

which is better to use?

It really depends on your requirement. onTouch gives you a Motion Event. This way you can do a lot of bizarre things, as it helps you share the state of movement. Just to name a few

  • ACTION_UP
  • ACTION_DOWN
  • ACTION_MOVE

These are the usual actions that we usually implement to get the result of desire, for example, dragging a view onto the screen.

OnClick, on the other hand, does not give you much, except that the viewing user interface interacts. onClick is a complete event consisting of focusing, clicking and releasing. Thus, you have little control over this. One side is very simple to implement.

do we need to implement both?

This is not necessary if you do not want to spoil your user. If you just need a simple click event, go to onClick. If you want more than just a click, go to onTouch. Performing both will complicate the process.

From the user's point of view, it’s imperceptible if you carefully implement onTouch to look like onClick.

+80
03 Feb '12 at 2:40
source share

The β€œTouch” event is when someone puts a finger on the screen. It is called during the movement of the finger, down, drag and up. A β€œClick” may not even appear on the screen. Maybe someone pressed the enter key.

Use OnTouchListener when you want to receive events from someone with your finger on the screen.

Use OnClickListener if you want to detect clicks.

+19
Feb 03 2018-12-12T00:
source share
  • onClickListener used whenever a click event occurs for any view, for example: click event for Button, ImageButton.

  • onTouchListener used whenever you want to implement Touch type functionality, for example, if you want to get the coordinates of the screen on which you are touching.

from white paper, definition for both:

  • onClickListner : onClickListner interface for the callback that is called when the view is clicked.
  • onTouchListener : onTouchListener interface for the callback that is called when a touch event is sent to this view. The callback will be called before the touch event is passed to the view.
+7
Feb 03 2018-12-12T00:
source share

One good reason to use ontouch events over onclick events is to get a faster response when the user clicks. If the onclick event suffers from a delay in response and continuation of the action. ontouch events are best for delivering high-performance mobile web applications.

+7
Mar 22 '13 at 15:42
source share

Prefer to use onTouch. Give an example: when you have ViewPager and TextView. if you implement setOnClickListener in textView, you will not be able to scroll ViewPager when touching / scrolling on TextView

+2
Jun 02 '15 at 0:13
source share

OnClickListener - used for the main purpose, when we just need a click from the user, that is, a button click, no drag and drop gestures

OnTouchListener is basically more subtle control than OnClickListener. It performs and acts when you press / release on the screen. It allows the user to combine moving, lowering, touching, dragging a finger or any gesture of movement on the screen.

0
Jun 19 '14 at 19:16
source share



All Articles