Reputation: 11
I'm a bit confused about the onTap method(s) and how they work with ItemizedOverlay. I want the user to tap on the map and then I place an OverlayItem (icon) where they tapped. Then I want them to tap that OverlayItem again to confirm the location.
I can add the OverlayItem to the map no problems by overriding
public boolean onTap(GeoPoint p, MapView mapView)
But then I want to capture the user tapping on that item by overriding
protected boolean onTap(int i)
The trouble is, when I override BOTH of these methods, the second method is never executed when I tap my icon item.
I've followed all the examples but I'm still stuck. Could someone give me an idea what I'm doing wrong please?
Thanks
Upvotes: 0
Views: 1105
Reputation: 11
Thanks for the reply. The super.onTap seems to be the thing I was missing. These are my methods, so you see the 'GeoPoint' version of onTap is the main entry point, and it works! The link I posted was also very helpful.
@Override
public boolean onTap(GeoPoint p, MapView mapView) {
// If it was the parent that was tapped, do nothing
if(super.onTap(p, mapView)) {
return true;
}
else {
lastClickedLocation = p;
mapView.getController().animateTo(lastClickedLocation);
if(markerItem == null) {
markerItem = new OverlayItem(lastClickedLocation, "", "");
items.add(markerItem);
}
else {
items.remove(markerItem);
markerItem = new OverlayItem(lastClickedLocation, "", "");
items.add(markerItem);
}
Utils.alert(parent.getApplicationContext(), parent.getResources().getString(R.string.tapAgainToConfirm));
populate();
return true;
}
}
/**
* Override the onTap(index) method
*/
@Override
protected boolean onTap(int i) {
parent.confirmLocation(items.get(i));
return true;
}
Upvotes: 1
Reputation: 1007349
I have not tried this, but I think it will work:
Try chaining to the superclass from the GeoPoint
-flavored onTap()
. That should give you the default processing of calling the index-flavored onTap()
. Override that method to find out when the user taps on an existing marker and return true
to indicate you handled the event. Back in the GeoPoint
-flavored onTap()
, if super.onTap()
returns true
, that means the event was handled by somebody (such as you). Therefore, if it is false
, add a marker at the supplied GeoPoint
.
Upvotes: 0