19

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?

Janusz
  • 187,060
  • 113
  • 301
  • 369
Artemiy
  • 482
  • 1
  • 3
  • 13

4 Answers4

10

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.

Anthony
  • 4,720
  • 1
  • 22
  • 9
  • 1
    Hi Anthony, Where did you find documentation stating that it is a snapshot? I've only come across answers by you stating this - but nothing in the Google docs (as limited as those tend to be). – Steven Jan 30 '13 at 00:29
  • 1
    There's a note in [the documentation](https://developers.google.com/maps/documentation/android/infowindows#custom_info_windows) that has this information. – Gray Feb 20 '14 at 16:10
8

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)

rockgecko
  • 4,127
  • 2
  • 18
  • 31
4

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();

        }
    });
0

CustomInfoWindowAdapter set tag:

mWindow.findViewById(R.id.chat).setTag("chatTag"); // button

and:

  @Override
public void onInfoWindowClick(Marker marker) {


   if(customInfoWindowAdapter.getInfoContents(marker).findViewById(R.id.chat).getTag().equals("chatTag")) {
      // any code here
   }
}
Javier Monzon
  • 59
  • 1
  • 1