0

I want my callback to be fired on every touch event for a particular view. I've found similar question: View.onTouchEvent only registers ACTION_DOWN event by there is no direct answer.

If true is returned from onTouch() then further events belonging to the same touch (eg. ACTION_MOVE) are reported, but flow is disrupted and normal event processing does not happen (eg. View is not entering in pressed state).

If false or super.onTouchEvent is returned then only ACTION_DOWN is reported but not other actions and normal processing happens correctly (eg. View is entering in pressed state). Unfortunately other callbacks like onInterceptTouchEvent() aren't called as well.

I want to be both notified on all touch events (ACTION_DOWN, ACTION_MOVE and so on) and not disrupt normal processing (eg. View should enter correct state when touched). How to achieve this behavior?

Community
  • 1
  • 1
koral
  • 2,513
  • 1
  • 32
  • 41

1 Answers1

0

You can try to extend your particular View and overwrite dispatchTouchEvent like this

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

And implement handleTouch to do whatever you want to do without disrupting the normal flow.

Ivo
  • 18,659
  • 2
  • 23
  • 35
  • 1
    Just return `super.dispatchTouchEvent(ev)` instead of true. – meredrica Oct 11 '13 at 11:12
  • Except when your actual view didn't consume the ACTION_DOWN you also wouldn't get the ACTION_MOVE. If you want to do something with that you need to call `super.dispatchTouchEvent(ev);` and return `true` – Ivo Oct 11 '13 at 11:16
  • Effects are respectively the same as in my question. If I return `true` I receive further `ACTION_MOVES` but normal processing does not happen and vice versa if there is `return super.dispatchTouchEvent(ev);` then normal processing happens but I don't receive further actions. – koral Oct 11 '13 at 11:40