Question

Actually I'm trying to implement an ontouchlistener into my android (1.5) application. therefore i implemented the "ontouchlistener" into the class, and then i put my code into the:

public boolean onTouchEvent (MotionEvent e){
 //code
}

The problem is, that if I am dragging over an (e.g.) Spinner or EditTextView than this Method isn't called. The only way to solve this which i figured out is to add an ontouchlistener to each of this views manually:

((Spinner)(findViewById(R.id.spinner1))).setOnTouchListener(tl);
((Spinner)(findViewById(R.id.spinner2))).setOnTouchListener(tl);

(tl is the ontouchlistener) So isn't there a way to catch the touch event before it gets to each of those views? thanks in advance

Ripei

Was it helpful?

Solution

What exactly do you want to do - do you want to:

  • Detect whole gestures in some Activity.
  • Detect touches only for a given View

If you want the former:

Take a look at this example: Fling gesture detection on grid layout.

Basically, you redirect all registered touch events to a GestureDetector. It understands what exactly is the user input (single tap, double tap, scroll, etc.) and calls the corresponding callback in a SimpleOnGestureListener, which you should implement.

If you want the latter:

You can either:

  1. Override the View's onTouchEvent().
  2. Implement and hook onTouchListener (if you want to get the touch before it's dispatched to it).

If you want to implement onTouchListener, you'll be doing your work not in the onTouchEvent() method, but in the interface's onTouch() method.

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top