/** * Creates and displays the balloon overlay by recycling the current balloon or by inflating it * from xml. * * @return true if the balloon was recycled false otherwise */ private boolean createAndDisplayBalloonOverlay() { boolean isRecycled; if (balloonView == null) { balloonView = createBalloonOverlayView(); clickRegion = balloonView.findViewById(R.id.balloon_inner_layout); clickRegion.setOnTouchListener(createBalloonTouchListener()); closeRegion = balloonView.findViewById(R.id.balloon_close); if (closeRegion != null) { if (!showClose) { closeRegion.setVisibility(View.GONE); } else { closeRegion.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { hideBalloon(); } }); } } if (showDisclosure && !showClose) { View v = balloonView.findViewById(R.id.balloon_disclosure); if (v != null) { v.setVisibility(View.VISIBLE); } } isRecycled = false; } else { isRecycled = true; } balloonView.setVisibility(View.GONE); List<Overlay> mapOverlays = mapView.getOverlays(); if (mapOverlays.size() > 1) { hideOtherBalloons(mapOverlays); } if (currentFocusedItem != null) { balloonView.setData(currentFocusedItem); } GeoPoint point = currentFocusedItem.getPoint(); MapView.LayoutParams params = new MapView.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, point, MapView.LayoutParams.BOTTOM_CENTER); params.mode = MapView.LayoutParams.MODE_MAP; balloonView.setVisibility(View.VISIBLE); if (isRecycled) { balloonView.setLayoutParams(params); } else { mapView.addView(balloonView, params); } return isRecycled; }