I got this error, too. However, calling mapView.invalidate() on the
enclosing map seemed to take care of this. I suspect that the map
caches the order of the overlays, and this comes out of sync when an
item is removed. Here is the following code I used:
public void clear()
{
ArrayList<oItem> items= this.items;
if (items.size() > 0)
{
items.clear();
this.setLastFocusedIndex(-1);
this.populate();
this.mapView.invalidate();
}
}
This worked for 1.5, Google APIs 3.
http://andmobidev.blogspot.com
On Jan 31, 1:35 pm, Eric Crump <[email protected]> wrote:
> I've seen all the posts about using setLastFocusedIndex(-1). I've
> tried that but my app is still crashing. I don't know what else to do
> to fix it. Any help is appreciated.
>
> public class UnitOverlay extends ItemizedOverlay {
>
> private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>
> ();
> private HashMap<String, Drawable> symbols = new HashMap<String,
> Drawable>();
> private String restClientURL;
>
> public UnitOverlay(Drawable defaultMarker, String restClientURL) {
> super(boundCenterBottom(defaultMarker));
> this.restClientURL = restClientURL;
> populate();
> }
>
> @Override
> public void draw(Canvas pCanvas, MapView pMapView, boolean pShadow)
> {
> super.draw(pCanvas, pMapView, false);
> }
>
> public void clearOverlay(){
> mOverlays.clear();
> setLastFocusedIndex(-1);
> populate();
> }
>
> public void addOverlay(GeoPoint loc, ViewItem item) {
> setLastFocusedIndex(-1);
> OverlayItem oi = new OverlayItem(loc, item.getName(), "");
> if(symbols.containsKey(item.getImageURL())){
> oi.setMarker(symbols.get(item.getImageURL()));
> }
> else{
> Bitmap b = RestClient.getImage(restClientURL +
> item.getImageURL());
> BitmapDrawable bd = new BitmapDrawable(b);
> symbols.put(item.getImageURL(), bd.getCurrent());
> if(b != null){
> oi.setMarker(bd);
> }
> else{
> Log.i("blah", "no image");
> }
> }
> mOverlays.add(oi);
> }
>
> public void populateOverlay(){
> setLastFocusedIndex(-1);
> populate();
> }
>
> @Override
> protected OverlayItem createItem(int i) {
> return mOverlays.get(i);
> }
>
> @Override
> public int size() {
> return mOverlays.size();
> }
>
> }
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en