Reputation: 2728
I have map view which contain a lot of pin of place , each pin can show balloon over its . but when I press another pin , the balloon of the old one isn't close automatic , so I want to clear balloon every time before other balloon will show
(I extends BalloonItemizedOverlay)
please help, thanks.
Upvotes: 0
Views: 738
Reputation: 7896
The following code removes all BalloonOverlayItems from the map:
MapView.removeViews(0, MapView.getChildCount());
It is the equivalent of MapView.getOverlays().clear() (used for regular overlays), the code above works for a map that contains Balloon overlays.
Upvotes: 2
Reputation: 234
Maybe it's too late, but I think I was facing the same problem today.
When you remove items by using mapView.getOverlays().clear()
, all items are removed.
But, if you look at the method 'createAndDisplayBalloonOverlay' in BalloonItemizedOverlay.java
you'll see the line mapView.addView(balloonView, params);
, so mapView
keep a reference of the balloon as child. That why your pin is gone but the balloon1 still show.
The quick fix will be to remove all instance ofBalloonOverlayView
with the methode mapView.removeViewAt()
after deleted items. Also depend of your implementation maybe you will need to keep the current displayed balloon.
Upvotes: 0
Reputation: 33792
From BallonItemizerOverlay.java
/**
* Sets the visibility of this overlay's balloon view to GONE.
*/
private void hideBalloon() {
if (balloonView != null) {
balloonView.setVisibility(View.GONE);
}
}
/**
* Hides the balloon view for any other BalloonItemizedOverlay instances
* that might be present on the MapView.
*
* @param overlays - list of overlays (including this) on the MapView.
*/
private void hideOtherBalloons(List<Overlay> overlays) {
for (Overlay overlay : overlays) {
if (overlay instanceof BalloonItemizedOverlay<?> && overlay != this) {
((BalloonItemizedOverlay<?>) overlay).hideBalloon();
}
}
}
Upvotes: 1