我正在尝试搜索包含某些数据的自定义 ItemizedOverlay ...当我尝试遍历 MapView 的所有叠加层时,我不断在 for 循环中收到 ConcurrentModificationException。
我希望有人知道这个问题的答案...
这是代码:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("Activityresult", "voor ok");
if(resultCode == RESULT_OK){
GeoPoint point = new GeoPoint(touchedPoint.getLatitudeE6(), touchedPoint.getLongitudeE6());
Car car = data.getExtras().getParcelable("car");
PinpointItem pinpoint = new PinpointItem(point, car, DropHostCarActivity.this);
CustomPinpointOverlay custom = new CustomPinpointOverlay(d, DropHostCarActivity.this);
custom.insertPinpoint(pinpoint);
List<Overlay> mapOverlays = mapView.getOverlays();
if (mapOverlays.size() > 1) {
removeSameCar(mapOverlays,car);
}
overlayList.add(custom);
mapView.invalidate();
}
}
private void removeSameCar(List<Overlay> mapOverlays, Car car) {
for(Overlay overlay: mapOverlays){
if(overlay instanceof CustomPinpointOverlay &&
((CustomPinpointOverlay) overlay).getItem(0).getCar().getNumberPlate().equals(car.getNumberPlate())){
overlayList.remove(overlay);
}
}
}