I'm trying to combine two operations in the android OnTouch listener, whereby one tap will do one thing and two taps will do another. I am using code to determine if a user had pinched the screen to allow it to be zoomed. I modified an answer given in a previous answer and this is what I came up with (I've removed superfluous code, as I wanted to illustrate the parts which work compared to the ones that don't):
myView.setOnTouchListener( new View.OnTouchListener()
{
myView.setOnTouchListener( new View.OnTouchListener()
{
private GestureDetector gestureDetector = new GestureDetector(getApplicationContext(), new GestureDetector.SimpleOnGestureListener()
{
@Override
public boolean onDoubleTap(MotionEvent e) {
// Stuff in here doesn't work
}
});
@Override
public boolean onTouch( View v, MotionEvent event )
{
if (event.getPointerCount() > 1)
{
// pinch to zoom stuff omitted - this works
}
else
{
if (action == MotionEvent.ACTION_UP)
{
//single touch logic
// code omitted
}
}
}
});
}
The parts in the GestureListener don't work, but the code within OneTouch does I'd personally had doubts about combining a gesturedetector within an OnTouchListener as it seemed a bit clumsy, but the answer in the previous forum ( DoubleTap in android ) seemed pretty neat.
There is another problem with the code, whenever I do an "action up" and release my fingers from the screen, the code labelled "single touch logic" is activated. How can this be, when the code for single touch logic is separate from the double touch/pinch logic? It seems I have two problems here!