Question

I am creating an Android application for visually impaired and am using a menu of buttons. When a user slides his fingers on the screen the application reads the button's captions. This is accomplished using onTouch events. When a user clicks a button, an action happens (change activity, or any other action) which is accompanied by a speech feedback. This is accomplished using onClick events.

The problem is that when clicking a button both events fire (onTouch and onClick) and the TTS begins to read the onTouch message, stops after half a second and starts the new message which was declared in the onClick event. How can I disable the firing of the onTouch when invoking onClick. I understand the problem because onTouch always precedes onClick, but I have no idea for a solution.

Thank you

Était-ce utile?

La solution

Simple answer dear avoid click event apply the tap event.

i also face the same problem so i know how to solve this.

just use this code.

First create gesture class.

class MyGestureDetector extends SimpleOnGestureListener 
{
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
    {
        return false;
    }
    @Override
    public boolean onDoubleTap(MotionEvent e) 
    {
        return true;
    }
    @Override
    public boolean onSingleTapUp(MotionEvent e) 
    {
        return true;
    }
}

Then create GestureDetector gestureDetector;
object and.

gestureDetector=new GestureDetector(myContext, new MyGestureDetector());

Then register with on touch event.

view.setOnTouchListener(this);

override the onTouch Method like this.

@Override
    public boolean onTouch(View view, MotionEvent event) 
    {
        Button b=(Button) view;
        gestureDetector.onTouchEvent(event);
        return true;
    }

Here Do Some task on onSingal tp and Double Tap.

Autres conseils

   public final OnTouchListener mOnTouchListener = new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent rawEvent) {
        return false;
    }
}; 

or

object.setOnTouchListener(null);

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top