2010年9月20日 星期一

ACTION_UP missing?

I am try to implement a custom VIEW for practice, and I got a strange issue: I want to handle the ACTION_UP event in onTouchEvent() method, but I cannot see the ACTION_UP event.

After some testing, I found the root course of this issue: ACTION_DOWN event must be handled before you received the ACTION_UP event.

Cause my view does not need to care about ACTION_DOWN, so I just put ACTION_UP check and return TRUE for it, otherwise return super.onTouchEvent() instead.

Seems Android makes a assumption that if you don’t care about ACTION_DOWN, you will not need ACTION_UP. And that’s why I cannot get the ACTION_UP event.

After I add a ACTION_DOWN checking and return TRUE, I can receive ACTION_UP as normal.

I don’t know if my guess is correct, I cannot find any document mention this assumption. But that’s the behavior I can see in my test code, and that really solve my issue.

沒有留言:

張貼留言