Ontouch event of OnTouchListener gets called twice in android
<p>I am creating an appliction in which line gets generated between two points given at runtime.The Problem that i see is that onTouch() is called twice for every click on my simulator.I know that two actions(ACTION_DOWN &amp; ACTION_UP) are checked.But i want my app to call onTouch() just once.Plz give some idea.Foll is my code i used</p>

<pre><code>SurfaceView surfaceview=new SurfaceView(getContext());
SurfaceHolder h = surfaceview.getHolder();
int action = event.getActionMasked();
        synchronized(h) {
            if (action == MotionEvent.ACTION_DOWN &amp;&amp; action!=MotionEvent.ACTION_CANCEL)// &amp;&amp; flag==true)
            {
                Log.d("TouchView","ACTION_DOWN ");
                Point pointer=new Point();
                pointer.x=(int) event.getX();
                pointer.y=(int) event.getY();
                touchPoint.add(pointer);
                view.invalidate();
                Log.d("MotionEvent.ACTION_DOWN", "point: " + pointer);
                action=MotionEvent.ACTION_CANCEL;
                flag=false;
            }
            else if(action == MotionEvent.ACTION_UP &amp;&amp; action!=MotionEvent.ACTION_CANCEL)// &amp;&amp; flag==true)
            {
                Log.d("TouchView","ACTION_UP");
                Point pointer=new Point();
                pointer.x=(int) event.getX();
                pointer.y=(int) event.getY();
                touchPoint.add(pointer);
                view.invalidate();
                Log.d(" MotionEvent.ACTION_UP", "point: " + pointer);
                action=MotionEvent.ACTION_CANCEL;
                flag=false;
            }
            else return false; 
</code></pre>
