Ishan
Ishan

Reputation: 3395

onClusterItemInfoWindowClick is not getting called for Google maps in Android

EDIT: This question is in reference to Google Maps on Android.

I am trying to make custom info window for markers with clustering. I followed the instructions given here https://stackoverflow.com/a/21964693/1641882

I did these :

Setup the cluster manager to act as info window adapter

// Setting custom cluster marker manager for info window adapter
    map.setInfoWindowAdapter(mClusterManager.getMarkerManager());
    mClusterManager.getMarkerCollection().setOnInfoWindowAdapter(new MyLocationInfoWindowAdapter());

Set a click listener for clusterItem info window

mClusterManager.setOnClusterItemInfoWindowClickListener(new ClusterManager.OnClusterItemInfoWindowClickListener<LocationMarker>() {
        @Override
        public void onClusterItemInfoWindowClick(LocationMarker locationMarker) {
            Toast.makeText(context, "info window Click", Toast.LENGTH_SHORT).show();
        }
    });

Here is my Info Window Adapter

private class MyLocationInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
    @Override
    public View getInfoWindow(Marker marker) {
        return null;
    }

    @Override
    public View getInfoContents(Marker marker) {
        TextView helloTextView = new TextView(getContext());
        helloTextView.setText("Hello Info contents");
        helloTextView.setClickable(false);
        return helloTextView;
    }
}

Upvotes: 2

Views: 1528

Answers (1)

Ishan
Ishan

Reputation: 3395

I found the solution. I am posting it here so that others can find it useful.

It seems that even after setting the InfoWindowAdapter to MarkerManager of my custom ClusterManager like this :

map.setInfoWindowAdapter(mClusterManager.getMarkerManager());

The click listener for info windows is still with the map object and not with mClusterManager.

So to respond to the info window clicks I needed to set it with map object only like this :

map.setOnInfoWindowClickListener(new MyMarkerInfoWindowClickListener());

The point to take home here is that the info window clicks doesn't get registered with cluster manager but remains only with map.

Upvotes: 6

Related Questions