Android dev: handling touch events on custom views

Embarrassingly this tripped me up for a while. In a custom view there were only single “click” events being called when a finger was dragged across the screen. This was due to the return value from the method being false (default in eclipse when you choice source: override methods. Changing it to true means that a constant stream of touch events are produced as expected.

public class FooView extends View {
  public boolean onTouchEvent(MotionEvent event) {
    // do stuff
    return true;

Leave a comment

Your email address will not be published.