Android ListView onTouchEvent doesn't give ACTION_DOWN

柔情痞子 提交于 2019-12-10 18:22:24

问题


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


回答1:


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 :-)




回答2:


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.



来源:https://stackoverflow.com/questions/9773855/android-listview-ontouchevent-doesnt-give-action-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!