0

i add those listeners to an imageView like this :

view.setOnTouchListener(clickEvent);
view.setLongClickable(true);
view.setOnLongClickListener(longclickEvent);

OnTouch event rises and OnlongClick did not. OnlongClick work only if i erase OnTouch event.

any idea please, thanks in advance.

habibhassani
  • 486
  • 1
  • 6
  • 15
  • 3
    Simple answer: You cannot have both. If you set an `OnTouchListener` all other click or long click listeners will not work anymore. If you need to use an `OnTouchListener` than you need to handle the click events manually. – Xaver Kapeller Feb 28 '15 at 21:30
  • 1
    Try returning `false` in your `clickEvent` (`onTouch`) implementation. – miselking Feb 28 '15 at 21:37

1 Answers1

1

If you haven't some MotionEvent to control, I recommend to you to use an ImageButton and set OnClickListener and OnLongClickListener. In this case you will have the same result you are trying to have with your code, but instead, this works. The problem of use OnTouchListener is that it will 'replace' the other click events. So, in the case you are doing something that can be done only with OnTouchListener, you can return true in each statement you need to be run in OnTouchListener, and return false before the last closing bracket to avoid that every touch on the screen will be handled by OnTouchListener.

Giorgio Antonioli
  • 15,771
  • 10
  • 45
  • 70