开发者

Can't make an ACTION_MOVE with the emulator

Even though I'm newbie with Android I'm feeling more noob than ever. I have my view that extends SurfaceView, and there I override the onTouchEvent and put this testing code inside:

if (event.getAction() == MotionEvent.ACTION_MOVE)
  {
   return true;
  }
  return false;

Then when I run the application in the emulator (using Eclipse) in debugging mode, there's no way I can make it return true. I click, keep clicked and drag, and then release, but it w开发者_如何学Goill always be event.getAction == 0 no matter what.

What am I missing?


You should return "true" in "OnTouchEvent" method to avoid this problem.


getAction() returns a combination of the actual action flag and the index of the pointer that generated that event (used for multitouch).

To have only the action part you can do an AND with MotionEvent.ACTION_MASK:

if (event.getAction() & MotionEvent.ACTION_MASK ==
                               MotionEvent.ACTION_MOVE) { ...

or if you're on API >= 8 you can directly use getActionMasked(). This is useful if you have to test it in a switch.

similar question here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜