1

I have different Markers based on their different information to show in custom infowindow. For that I have use different class for each infowindow content.

I can see different Markers in my map. But I tap on them, only the lastly built marker's information is showing. Basically the infowindow content is same. Also I noted that when I tap, it does not call the relevent infowindow instead its calling lastly created infowindow's getInfoContents(Marker arg0). But I receive the correct marker inside to getInfoContents(Marker arg0) to the lastly added marker.

We can have only one infowindow implementation for all the markers in the map? And based on the marker identification should I implement the different contents?

Marker type A implementation

 public class MapGoogleOverlayV2 {

    private ViewGroup infoWindow;

    public boolean onTap() {


    infoWindow  = (ViewGroup)((Activity)mContext).getLayoutInflater().inflate(R.layout.info_window_layout, null);


    /*Custom info window implementation is below */
    googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {

        @Override
        public View getInfoWindow(Marker arg0) {

            return null;
        }

        @Override
        public View getInfoContents(Marker arg0) {

            // set title
            ((TextView)infoWindow.findViewById(R.id.title)).setText("Test text");

            // set freeText
            ((TextView)infoWindow.findViewById(R.id.text)).setText(Long.toString("1"));


              return infoWindow;

        }
    });
   }
}

Marker B implemented in another class with different info. and I am calling onTap()

I create two markers with different information by calling their own implementation and display that in map.

only problem is they both show same information which is last marker's information.

user2771655
  • 1,052
  • 3
  • 20
  • 38

1 Answers1

1

Setters (and GoogleMap.setInfoWindowAdapter seems to be a setter) replace what was there before.

If you call onTap in both classes, only the last InfoWindowAdapter survives.

Instead you need to set only one InfoWindowAdapter and decide for which Marker you need to show info window based on getInfoContents parameter (Marker arg0).

MaciejGórski
  • 22,187
  • 7
  • 70
  • 94
  • Thanks for the info. I changed my solution accordingly. – user2771655 Nov 05 '13 at 03:50
  • I tried to call the "googleMap.setInfoWindowAdapter(new InfoWindowAdapter() { " in public boolean onMarkerClick(final Marker marker){} but it is not showing the infowindow. That means infowindow build before map display? We can not set values to infowindow after map load? – user2771655 Nov 05 '13 at 08:24
  • 1
    I answer to my own question. Yes we can set new infomation on the fly. I just call the infoWindowAdapter(new InfoWindowAdapter()... method again with new data when ever I have an update data. – user2771655 Nov 08 '13 at 02:29