home / blog

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 {
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    // do stuff
    return true;
  }
}
This entry was posted in geek and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.