I've came across something strange, I want to listen for clicks and when it happens I want to get it's directions, but the click seems to happen three times, what is the cause of it?
this.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
int x = (int) motionEvent.getX();
int y = (int) motionEvent.getY();
Log.i(LOGGING_CONST, "click performed x: " + x + " y: " + y);
}
}
});
@Override
public boolean performClick() {
return super.performClick();
}
Logcat after one click:
I/GAME_VIEW_CLASS:: click performed x: 481 y: 804
I/GAME_VIEW_CLASS:: click performed x: 481 y: 804
I/GAME_VIEW_CLASS:: click performed x: 481 y: 804
Because you are listening touch events and touch events triggers on every finger movements. Try to listen onDown event. As an example;
this.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
int x = (int) event.getX();
int y = (int) event.getY();
Log.i(LOGGING_CONST, "click performed x: " + x + " y: " + y);
break;
}
return true;
}
});