Android MotionEvent only detects ACTION_MOVE
As per the android docs MotionEvent
: A crash occurred during a print gesture (between ACTION_DOWN
and ACTION_UP
). The movement contains the most recent point, as well as any intermediate points since the last event or movement.
so when i apply setOnTouchListene
on my view works fine, it gives me ACTION_DOWN
, ACTION_UP
andACTION_MOVE
but my problem is that I just want to ignore events ACTION_DOWN
exactly before ACTION_MOVE
. Because the event ACTION_MOVE
only happens after the event ACTION_DOWN
according to its docs.
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, is there any reason to ignore the event ACTION_DOWN
. Since the user only wants to navigate, do not want to click, and ACTION_MOVE
also appears ACTION_DOWN
before he does it himself.
Thank...
source to share
As per your comment - you can play 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 a move
}
counter = 0;
break;
}
return false;
}
});
source to share