habibhassani
habibhassani

Reputation: 506

onTouchListiner & OnLongClickListener on ImageView didn't work

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.

Upvotes: 0

Views: 140

Answers (1)

Giorgio Antonioli
Giorgio Antonioli

Reputation: 16214

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.

Upvotes: 1

Related Questions