3

As per android MotionEvent documents: A change has happened during a press gesture (between ACTION_DOWN and ACTION_UP). The motion contains the most recent point, as well as any intermediate points since the last down or move event.

ACTION_MOVE Android doc

so when i apply a setOnTouchListene on my view is perfectly works, It give me ACTION_DOWN, ACTION_UP, and ACTION_MOVE

but my problem is i just want to ignore a ACTION_DOWN events exactly before ACTION_MOVE. Because ACTION_MOVE event occur only after the ACTION_DOWN event as per its documents.

my coding:

      button.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                switch (event.getAction() & MotionEvent.ACTION_MASK) {
                    case MotionEvent.ACTION_DOWN:
                        Log.e("Mouse: ", "Click");
                        break;
                    case MotionEvent.ACTION_MOVE:
                        Log.e("Mouse: ", "Move");
                        break;
                }

                return false;
            }
        });

So, there is any why to ignore ACTION_DOWN event. Because user only want to move not want to click, and ACTION_MOVE is also occur ACTION_DOWN before it execute it self.

Thanks...

Community
  • 1
  • 1
Kalpesh Rajai
  • 2,040
  • 27
  • 39

1 Answers1

5

According to your comment - you can play with counter. For example:

private static int counter = 0;
...  
button.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {


            switch (event.getAction() & MotionEvent.ACTION_MASK) {
                case MotionEvent.ACTION_DOWN:
                    Log.e("Mouse: ", "Click");
                    break;
                case MotionEvent.ACTION_MOVE:
                    counter++; //check how long the button is pressed
                    if(counter>10){
                       Log.e("Mouse: ", "Move");
                    }

                    break;
                case MotionEvent.ACTION_UP:
                    if(counter<10){
                       //this is just onClick, handle it(10 is example, try different numbers)
                    }else{
                       //it's a move
                    }
                    counter = 0;
                    break;
            }

            return false;
        }
    });
Alexander Tumanin
  • 1,638
  • 2
  • 23
  • 37
  • you suggestion is good, but in your code user have to wait for response, and i want to give the response immediately.. And its not be good for my project, Thanks for response. – Kalpesh Rajai Jul 31 '15 at 17:08
  • Best Answer for those who wants to use MOVE properly because sometimes ACTION.MOVE is called even when user touch screen simply ...So to notice proper MOVE .Counter is best solution. – karanatwal.github.io Mar 09 '17 at 08:37