0

I am learning how to make android apps, and I can't figure out how to implement a kind of OnMouseMoved event in android.

I've tried using an OnTouchListener, but It doesn't update when I touch, hold and move. It only updates when I tap a different points. Like this:

public boolean onTouch(View v, MotionEvent event) {
    int x = (int) event.getX();
    thread.getGameState().touch(x);
    return false;
}

I've tried this

@Override
public boolean onTouch(View v, MotionEvent event) {
    int x = (int) event.getX();
    if(event.getAction() == MotionEvent.ACTION_MOVE) {
        thread.getGameState().touch(x);
    }
    return false;
}

But this doesn't even respond at all to touch, maybe the point i'm getting from the event is an old point, and not the new drag point?

thread.getGameState().touch(x); sets the x-value of and object, which should make it like dragging.

Edward Falk
  • 9,991
  • 11
  • 77
  • 112
Spencer H
  • 450
  • 1
  • 6
  • 17

1 Answers1

0

You must return true in onTouch() to tell Android that you will handle the complete touch event, so you can receive events after ACTION_DOWN:

@Override
public boolean onTouch(View v, MotionEvent event) {
    int x = (int) event.getX();
    if(event.getAction() == MotionEvent.ACTION_MOVE) {
        thread.getGameState().touch(x);
    }
    return true;
}
Mohamed_AbdAllah
  • 5,311
  • 3
  • 28
  • 47