Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ListView onTouchEvent doesn't give ACTION_DOWN

In order to have list reordering functionality I turned to this implementation.

My problem is that when I try to drag an item in my ListView, I don't get the ACTION_DOWN event. Instead, for a single smear down motion I get 2 ACTION_MOVE events (action=0x00000002) and a single ACTION_UP event (action=0x00000001) in this order.

I've looked at similar questions but it seems like everyone has the opposite problem, getting only ACTION_DOWN events. Can anyone think of why this is happening?

Thanks, Yoel

like image 573
yoel Avatar asked Feb 19 '26 19:02

yoel


2 Answers

I was using the same code.

My problem was also that something was consuming the event and I didn't managed to found what was it... but i managed to solve it using onInterceptTouchEvent to return true on the events i needed on onTouchEvent.

Problem solved :-)

like image 81
neteinstein Avatar answered Feb 25 '26 12:02

neteinstein


It turns out I needed to add this small piece of code:

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    return super.onInterceptTouchEvent(ev);
}

Now I get the ACTION_DOWN events in the OnTouchEvent function and it all works fine.

like image 34
yoel Avatar answered Feb 25 '26 12:02

yoel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!