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
What exactly do you want to do – do you want to:
Activity.ViewIf 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:
onTouchEvent().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 theonTouchEvent()method, but in the interface’sonTouch()method.Hope that helps.