I'm adding an InfoWindowAdapter with a custom layout to the Android Google Maps API v2 based map fragment. I've put a button in the view I return from getInfoWindow() and while it shows up perfectly fine, when I click on said button the window itself registers a click (blinking with a yellowish tint as usual) while the button does not.
How can I make a button in the info window "clickable"? And, by extension, any view inside an info window?
Instead, listen for marker click events with OnMarkerClickListener and display your own complete view directly. It may be a bit more work to anchor it to the location of the marker, however. Try PopupWindow with showAtLocation(View parent, int gravity, int x, int y)
While you can set an info window to be an arbitrary view using GoogleMap.setInfoWindowAdapter(), the info window that is rendered on the map is not a live view. Instead, it is a snapshot of the view at the time the view was returned by the adapter (see here). So, unfortunately it doesn't behave like a standard view once it is placed on the map.
Maybe you can set a customize AlartDialog in InfoWindowClickListener to switch something event
map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
public void onInfoWindowClick(Marker marker) {
String[] items={"onefunction","twofunction"};
AlertDialog.Builder itemDilog = new AlertDialog.Builder(context);
itemDilog.setTitle("");
itemDilog.setCancelable(false);
itemDilog.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
switch(which){
case 0:{
onefunction();
}break;
case 1:{
twofunction();
}break;
}
}
});
itemDilog.show();
}
});
来源:https://stackoverflow.com/questions/13706925/adding-a-button-to-a-custom-infowindowadapter-view-that-can-register-clicks