super(onTap (GeoPoint, Mapview)) always returning false
So, 开发者_运维技巧I wanted to Log a message whenever the user clicks on an overlay item and a dialog whenever the user clicks anywhere else on the screen. I read online that the best way to do it would be to call the super(onTap (GeoPoint, Mapview)). If it returns true I'd log, and display the dialog if otherwise. However I checked the output of the super call and it seems to return false irrespective of where the user clicks. Can anyone explain why or a possible solution?
You have to also handle onTap in the overlay itself (and return true there). I don't think any overlay handles onTap on it's own - you have to derive from the base class and override onTap() method of the overlay itself. Some of them do some calculations to see where you tapped, but they do not handle it.
For example if you derive from ItemizedOverlay, you got an additional method that you should override in your subclass:
@Override
protected boolean onTap(final int index) {
Log.d(...);
return true;
}
ItemizedOverlay already calculates where you tapped and in case you tapped inside one of the items, the new onTap(int) method is called with the index of item tapped. If you return true from this method, then the onTap(GeoPoint, MapView) will get true when calling super()..
@Override
protected boolean onTap(GeoPoint p, MapView m) {
if (!super.onTap(p,m)) {
// show dialog here ....
}
}
精彩评论