Issue on removing item from clustermanager

前端 未结 5 469
鱼传尺愫
鱼传尺愫 2020-12-16 01:44

In my Android application, I have to delete and re-add a cluster item in my GoogleMap, that represents my current location. But when I run this code:

cluster         


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-16 02:14

    Here is how I did it:

    @Override
    public void removeItem(T item) {
        final QuadItem quadItem = new QuadItem(item);
        synchronized (mQuadTree) {
            mItems.remove(quadItem);
            mQuadTree.remove(quadItem);
        }
    }
    

    I also implemented equals() and hashCode() in QuadItem as it is recommended in the TODO of the NonHierarchicalDistanceBasedAlgorithm source code:

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof QuadItem)) {
            return false;
        }
    
        QuadItem quadItem = (QuadItem) o;
    
        return mClusterItem.equals(quadItem.mClusterItem);
    
    }
    
    @Override
    public int hashCode() {
        return mClusterItem.hashCode();
    }
    

    Finally, I implemented equals() and hashCode() in my ClusterItem's descendant class.

提交回复
热议问题