title: Changing clustermanager item icon in android google maps
body: <p>I have a google maps in my android app. It is full of markers, it clusters the markers... in a few words, a fully usable map. </p>
  
  <p>What i want to do it's simple. When user tap on clusterItem, I want to change the icon to a selected one. (simply, same marker but with different color). </p>
  
  <p>How I am using a lot of markers on screen, It's imposible to clean the map and add the markers everytime a mark is clicked. </p>
  
  <p>So: </p>
  
  <pre><code>mClusterManager.setOnClusterItemClickListener(new ClusterManager.OnClusterItemClickListener&lt;MyItem&gt;() {
      @Override
      public boolean onClusterItemClick(MyItem myItem) {
          if (oldItemSelected != null) {
              mClusterManager.removeItem(oldItemSelected);
              oldItemSelected.setItemAsNotSelected();
              mClusterManager.addItem(oldItemSelected);
          }
  
          mClusterManager.removeItem(myItem);
          myItem.setItemAsSelected();
          mClusterManager.addItem(myItem);
          mClusterManager.cluster();
  
          oldItemSelected = myItem;
          return true;
      }
  });
  </code></pre>
  
  <p>The idea is to remove the item clicked from the map, set it to "selected", add the new item and refresh the map with .cluster method. </p>
  
  <p>What happens: The item doesn't change, sometimes the item is "duplicated" and the selected is behind the "normal" item. </p>
  
  <p>This is how I set up cluster manager: </p>
  
  <pre><code>mClusterManager = new ClusterManager&lt;MyItem&gt;(this, map);
  mClusterManager.setRenderer(new MyItemRenderer());
  mClusterManager.setAlgorithm(new GridBasedAlgorithm&lt;MyItem&gt;());
  map.setOnMarkerClickListener(mClusterManager);
  </code></pre>
  
  <p>And this is the item renderer: </p>
  
  <pre><code>private class MyItemRenderer extends DefaultClusterRenderer&lt;MyItem&gt; {
      public MyItemRenderer() {
          super(getApplicationContext(), map, mClusterManager);
      }
  
      @Override
      protected void onBeforeClusterItemRendered(MyItem myItem, MarkerOptions markerOptions) {
          markerOptions.title(myItem.getName());
          markerOptions.snippet(myItem.getAddress());
          markerOptions.icon(BitmapDescriptorFactory.fromResource(myItem.getIcon()));
      }
  
      @Override
      protected boolean shouldRenderAsCluster(Cluster cluster) {
          return cluster.getSize() &gt; 1;
      }
  
      public Marker getMarker(MyItem item) {
          return super.getMarker(item);
      }
  }
  </code></pre>
  
  <p>Is there any way to do this without having to re-paint every item in the map? </p>
  
  <p></p>
  
  <pre><code>public class MyItem extends DefaultClusterRenderer&lt;WifiSpotItem&gt; {
  
      private HashMap&lt;Integer, Marker&gt; markerWifiSpots = new HashMap&lt;&gt;();
  
      public MyItem(Context context, GoogleMap map, ClusterManager&lt;WifiSpotItem&gt; mClusterManager) {
          super(context, map, mClusterManager);
      }
  
      @Override
      protected void onBeforeClusterItemRendered(WifiSpotItem wifiSpotItem, MarkerOptions markerOptions) {
  
          if (markerOptions != null &amp;&amp; wifiSpotItem != null) {
              markerOptions.title(wifiSpotItem.getName() != null ? wifiSpotItem.getName() : Constants.EMPTY_STRING);
              markerOptions.snippet(wifiSpotItem.getAddress() != null ? wifiSpotItem.getAddress() : Constants.EMPTY_STRING);
              markerOptions.icon(BitmapDescriptorFactory.fromResource(wifiSpotItem.getIcon()));
          }
      }
  
      @Override
      protected void onClusterItemRendered(WifiSpotItem clusterItem, Marker marker) {
          markerWifiSpots.put(clusterItem.getId(), marker);
          super.onClusterItemRendered(clusterItem, marker);
      }
  
      @Override
      protected boolean shouldRenderAsCluster(Cluster cluster) {
          return cluster.getSize() &gt; 4;
      }
  
      public Marker getMarker(WifiSpotItem item) {
          return super.getMarker(item);
      }
  
      public Marker getMarker(int id) {
          Marker item;
          if (markerWifiSpots != null) {
              item = markerWifiSpots.get(id);
          } else {
              item = null;
          }
          return item;
      }
  }
  </code></pre>