I am trying to implement onTouchEvent on MapView to update geopoints but when I touch a screenwith the catching only ACTION_UP, it fires 3 times. How to execute my code once in this condition?
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
int action = event.getAction();
if (action == MotionEvent.ACTION_UP) {
Log.e("Touch", Integer.toString(event.getAction()));
//All 3 fires has index 1 that concern to ACTION_UP
//Below will be AsyncTask call
}
return false;
}
From the method-signature, I take it that your example is from an overwritten
Overlay? If so, it’s documentation states:This is standard android behavior for almost every event (onTouch, onKey, etc). If the event was handled (in your case, you started your AsyncTask), you should return
true, so Android knows that it has been handled.Since you are always returning
false, the framework does not know if it has been handled and dispatches the Action further down the event-handling chain. I’m not sure why it’s exactly three times.So, if you successfully handled the event, return
true.