what want:
i want map marker @ user´s current location , 10 more, loaded in asynctask database after loading map.
what doenst work
everything working fine, except 10 additional markers. loaded them db, added them list of overlayitems, , invalidated map - still aren´t shown.
update: works now: creating itemizediconoverlay after loading additional items in asynctask items shown , work inteded.
additionally, list of overlayitems initialized 0 objects (obviously), after add 1 overlayitem, contains 1 overlayitem + 11 more null-objects (or null-refernces? null-items? what´s correct term?)
my question
1) @ list of overlayitems: after loading everything, there still 1 null-object, thought might cause problems, didnt. (tested full list, no difference)
why list initialized 0 items, when add one, contains 12 items? (11 null, 1 "real" item) (code below)
2) [solved] far know, if add overlayitems list , invalidate map, should shown. if add items second list, , "overwrite" first 1 second one, still work? (as it´s not same object anymore, reference list2, right?)
update: creating itemizediconoverlay after loading additional items in asynctask items shown , work inteded.
full code
creating map
mresourceproxy = new defaultresourceproxyimpl(getapplicationcontext()); mapview.settilesource(tilesourcefactory.mapnik); mapview.setbuiltinzoomcontrols(true); mapview.setmultitouchcontrols(true); mapcontroller = this.mapview.getcontroller(); mapcontroller.setzoom(25); geopoint center = new geopoint(datamanager.glat, datamanager.glon); mapcontroller.setcenter(center); // items = null items = new arraylist<overlayitem>(); // items still empty items.add(new overlayitem("here", "sampledescription", center)); // now, items contains 1 overlayitem, 11 empty (null) items this.mlocationoverlay = new itemizediconoverlay<overlayitem>(items, new itemizediconoverlay.onitemgesturelistener<overlayitem>() { @override public boolean onitemsingletapup(final int index, final overlayitem item) { intent intent=new intent(); intent.putextra("newshopname", item.mtitle); intent.putextra("newshopadd", item.mdescription); setresult(result_ok, intent); finish(); return true; } @override public boolean onitemlongpress(final int index, final overlayitem item) { toast = toast.maketext(shopchooseactivity.this, item.mtitle + ", " + item.mdescription, toast.length_long); toast.show(); return false; } }, mresourceproxy); this.mapview.getoverlays().add(this.mlocationoverlay); mapview.invalidate(); loadmap = new loadchooseshop(shopchooseactivity.this, items).execute();
updating items new list of overlayitems asyntask
items = loadmap.get(); if(items != null) mapview.invalidate();
regarding new items not showing in itemizediconoverlay - method using add items()? reason looks additem(location, item) method not call populate() internal list never gets updated. use additem(item) method now. should point out itemizediconoverlay user-submitted class , starting point solution.
you mention having nulls in item list. way java's arraylist works. list backed immutable array when backing array full , want add new item, list has create new larger backing array. since expensive operation, new array double size of old one. unused "slots" in backing array set null. thing matters returned mitemlist.size().
Comments
Post a Comment