In My Android map application, I have some cluster icons. whenever the cluster icon is pressed i want to display a popup infobox with text and button. If we pressed the button, it will lead to next activity.
private void drawInfoWindow(Canvas canvas, MapView mapView, boolean shadow,
int x, int y) {
if (isSelected_) {
Point selDestinationOffset = new Point();
mapView.getProjection().toPixels(cluster_.center_,
selDestinationOffset);
// Setup the info window with the right size & location
int INFO_WINDOW_WIDTH = 125;
int INFO_WINDOW_HEIGHT = 25;
RectF infoWindowRect = new RectF(0, 0, INFO_WINDOW_WIDTH,
INFO_WINDOW_HEIGHT);
infoWindowRect.offset(x, y);
// Draw inner info window
canvas.drawRoundRect(infoWindowRect, 5, 5, getInnerPaint());
// Draw the MapLocation's name
int TEXT_OFFSET_X = 10;
int TEXT_OFFSET_Y = 15;
canvas.drawText(cluster_.number+" Incidents", x + TEXT_OFFSET_X, y
+ TEXT_OFFSET_Y, getTextPaint());
}
}
This shows only a small textview like popup window. But i want to display a popup infobox with text and button. Please provide me the best way….
Thanks…
You can use a custom layout xml file to create a overlay on mapview, instead of using canvas.
Create a xml file for your overlay(I use overlay_pin_layout.xml here). For example, a linearlayout which has a textview on the top and a button on the bottom.
Add this overlay to where you want.
// Inflate your overlay from xml file
View overlayPin = getLayoutInflater().inflate(R.layout.overlay_pin_layout, null);
// Set the textview
((TextView)(overlayPin.findViewById(R.id.textview_overlayerpin))).setText(YOUR_TEXT);
// set button touch listener
((Button)(overlayPin.findViewById(R.id.button_overlayerpin))).setOnLongClickListener(
new View.OnLongClickListener() {
// add your overlay on mapview by geopoint
overlayPin.setLayoutParams(new MapView.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT,
new GeoPoint(YOUR_LAT, YOUR_LON),
MapView.LayoutParams.BOTTOM_CENTER));
mapView.addView(overlayPin);
For a pop-up like animation , try this one.
Create a anim folder in res, if you do not have one.
Create a xml with the code below in anim folder. I call it animation_pop_up.xml.
When you add overlayPin on mapview, play the animation.