Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between OnTouch and OnClick Android

Tags:

android

Is there any difference between OnTouchListener and OnClickListener? I am not asking from programming point of view, but from User Experience point of view.

Which one is better to use?

Do we need to implement both?

like image 713
Nixit Patel Avatar asked Feb 03 '12 01:02

Nixit Patel


3 Answers

which one is better to use?

It really depends on your requirement.

onTouch gives you Motion Event. Thus, you can do a lot of fancy things as it help you separate state of movement. Just to name a few:

  • ACTION_UP
  • ACTION_DOWN
  • ACTION_MOVE

Those are common actions we usually implement to get desire result such as dragging view on screen.

On the other hand, onClick doesn't give you much except which view user interacts. onClick is a complete event comprising of focusing,pressing and releasing. So, you have little control over it. One side up is it is very simple to implement.

do we need to implement both?

It is not necessary unless you want to mess up with your user. If you just want simple click event, go for onClick. If you want more than click, go for onTouch. Doing both will complicate the process.

From User point of view, it is unnoticeable if you implement onTouch carefully to look like onClick.

like image 155
PH7 Avatar answered Oct 31 '22 02:10

PH7


A "Touch" event is when someone puts their finger on the screen. It gets called throughout the movement of the finger, down, drag, and up. A "Click" need not even come from the screen. It could be someone pressing the enter key.

Use OnTouchListener when you want to receive events from someone's finger on the screen.

Use OnClickListener when you want to detect clicks.

like image 26
Thomas Dignan Avatar answered Oct 31 '22 03:10

Thomas Dignan


  • 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.

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.
like image 34
Lucifer Avatar answered Oct 31 '22 02:10

Lucifer