5

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

Community
  • 1
  • 1
bilal.otm
  • 127
  • 1
  • 2
  • 9
  • possible similar to http://stackoverflow.com/questions/6742083/difference-between-ontouchlistener-and-onclicklistener – Auto-Droid ツ Mar 06 '14 at 12:54
  • possibly same question https://stackoverflow.com/questions/9122679/difference-between-ontouch-and-onclick-android – praveen Mar 06 '14 at 12:57
  • have you tried this https://www.google.com/#q=onclicklistener%20and%20ontouchlistener%20android – Auto-Droid ツ Mar 06 '14 at 12:58
  • [link](http://stackoverflow.com/questions/9122679/difference-between-ontouch-and-onclick-android) explains the second part of my question, thx for sharing. But i am also looking for performance differences, which is faster to respond on the view – bilal.otm Mar 06 '14 at 13:46
  • @Eonasdan and other members: I have edited my question to narrow it down. Kindly reopen the question. I want to get feedback for performance between the two. – bilal.otm Mar 06 '14 at 17:39

2 Answers2

9

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.

marcinj
  • 48,511
  • 9
  • 79
  • 100
Shadow
  • 6,864
  • 6
  • 44
  • 93
1

setOnTouchListener gives you a chance for something to respond before the view does, whereas

setOnClickListener is fired after the view responds.

pratiti-systematix
  • 792
  • 11
  • 28