1

Why is the android onclick listener for any views which we listen using setOnClickListener() is not working as expected, I mean onclick similar to desktop mouse event, onclick should be fired when mouse DOWN and UP events are triggered at the same location, but in case of android, after ACTION_DOWN if I move a little and release touch, I still get onclick fired. This is causing some unwanted effect on my TextView, which has links.

Is it because there will be always slightest difference in up and down coordinates? the reason for poor implementation.

USE CASE

Suppose in onclick I need to toggle ActionBar visibility but I do not want that to happen when I swipe which again fire onclick. For I was hoping for a clean code using android inbuilt options instead of using flags around touch listeners.

duckduckgo
  • 1,280
  • 1
  • 18
  • 32
  • 1
    How are you handling swipes? The detection of a swipe should prevent an onClick from firing. – Eborbob Jun 17 '15 at 11:55
  • i have swipe gesture in a parent view (ScrollView) also this example is not the best and situation is quite entangled. – duckduckgo Jun 17 '15 at 12:06
  • Take a look at http://stackoverflow.com/questions/13324366/how-to-disable-onclick-listener-while-swiping-a-view-in-android – Eborbob Jun 17 '15 at 12:26
  • like you said it will work using gesture and i have tried that but i want to know why does onclick work like this, i am not fully satisfied yet. once i am then i will try other options happily – duckduckgo Jun 17 '15 at 12:34

1 Answers1

0

The onClick method is called on the release (ACTION_UP).

If you want to track the DOWN and UP actions yourself you can use an onTouchListener instead (see http://developer.android.com/reference/android/view/View.OnTouchListener.html).

Eborbob
  • 1,905
  • 1
  • 15
  • 30
  • i just tried clicking the this browsers link the way you suggest and it didnt work, i can use other listeners or gestures but i am worried it may have different callback order which is critical in my case. – duckduckgo Jun 17 '15 at 11:27
  • I wasn't thinking about web browsers. Perhaps you could give more information about what you are trying to do? – Eborbob Jun 17 '15 at 11:34