Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android | What is the difference between setOnClickListener and setOnTouchListener? [closed]

What is the difference between setOnClickListener and setOnTouchListener?

Interms of:

Edited:

  1. Performance wise, which is faster to load/respond on the view, and
  2. Preferable Choice, this similar question, answers my second part very well.

Thanks

like image 720
bilal.otm Avatar asked Mar 06 '14 12:03

bilal.otm


People also ask

What is setOnTouchListener?

setOnTouchListener gives you a chance for something to respond before the view does, whereas. setOnClickListener is fired after the view responds. Follow this answer to receive notifications.

How does setOnClickListener work?

How does setOnClickListener do in android? In Android, the OnClickListener() interface has an onClick(View v) method that is called when the view (component) is clicked. The code for a component's functionality is written inside this method, and the listener is set using the setOnClickListener() method.


1 Answers

OnTouch is Motionevent. You can drag up,down,left and right. But OnClick is simply focusing,pressing and releasing. When you want to get co-ordinates of screen where you touch the screen, use touchlistener. Just a click event for button and imageview,use OnClickListener.

like image 200
Shadow Avatar answered Nov 15 '22 09:11

Shadow