Equivalent of com.google.android.maps.ItemizedOverlay.populate() for OpenStreeMaps (OSMDroid) - android

Any idea what's the equivalent of com.google.android.maps.ItemizedOverlay.populate() method in case of OpenSteeMapViewItemizedOverlay ?

There doesn't seem to be one. The data you pass into the constructor is already a list of OverlayItem objects. In the standard ItemizedOverlay, you must call populate(), so that the overlay iterates over the list of data and calls createItem() to create OverlayItems for each piece of data but in OpenstreetMapViewItemizedOverlay you have already create the OverlayItems so you don't need that step. The drawback I see though is that you cannot change the overlay once you create it though.

Related

Access List from ParseQueryAdapter

So, I am running up against a limitation of the Parse SDK here, and I don't know how to proceed.
I have a ListView that I am setting the adapter to from a subclass of the ParseQueryAdapter, which itself extends the BaseAdapter class.
Normally with an adapter, I pass the list along to the Adapter constructor in order to get access to the list I am dealing with, so that I can call getCount, getItem, etc. by accessing the size/index of that ArrayList.
I can't do that with the ParseQueryAdapter because it takes a ParseQueryFactory as part of the constructor, and it doesn't resolve it's items until they are fetched from the Parse app online...
Now the ParseQueryAdapter does have a List of Objects, which is exactly what I need, expect that it is Private... so even though the getItem() and getCount() methods exist, there is no way - AFAIK - to use them, as I have no access to the dataset that is fuelling my adapter...
Further to this, I would normally use getView(), which returns a position alongside my View, and everything would be snappy. Except Parse overrides that and provides a getItemView() method which resolves the Parse Object that is fetched from the cloud and passes it instead of the integer for position...
So, two questions here:
1) Is there another way in which I can access the list that is feeding an adapter ? I can hack a way to pass the resolved query into a list and pass that into the adapter later, by listening to addOnQueryLoadListener(), but that seems bad design and might take a while, handcuffing my UI.
2) Am I being naive in my understanding of how to use get getItem() and getCount() methods ?

Passed by reference or copy ArrayList

when I share an array list from the Main Activity to an Custom View for example will it be passed by reference or copy, my doubt is if the MainActivity add new elements to this list that was passed the Custom View will get the change. I want to build an application that the main activity will be processing a lot of data and putting this in an array, this array will be passed to a custom view that through canvas will draw a graph with the information inside of the list that was passed, so that is why this information is so important. Any kind of help will be precious, Cheers.
It is passed by reference yes. All objects are. You can read all about it HERE

removing specific overlays from mapview

my problem is as follows.
I am creating multiple itemized overlays. (because every overlay gets a different drawable)
I customized the itemized overlay class, but when i add it to the mapview overlays, the class is transformed into an overlay class.
to make it worse i got 3 classes creating overlays on the same map. each class represents an item on the map with it's own intelligence behind it.
the problem i now have is that i want to remove an overlay, but i can not be sure that the index i inserted it on, is also the index it has when i try to remove it. (the other classes might have inserted an overlay in the mean time)
the classes are self updating, so i do not want a solution that fires an update or delete event from the main class. (the whole point is to add a class and forget about it)
so my question would be: how can i identify which layer is which when i want to call a remove on that layer. i think the information is available, but i do not know how to get to it.
this is the code i am using to add the overlay
OverlayItem overlayitem = new OverlayItem(p,myNaam ,myOmschrijving );
LocationOverlay = new MyLocationOverlay(drawable, myContext);
LocationOverlay.SetLocation(i,overlayitem);
myOverlays.add(LocationOverlay);
You can set a certain integer as a position for every overlays
something like that :
mapView.getOverlays().add(0,myScaleBarOverlay);
and when you want ro remove this call:
mapView.getOverlays().remove(0);
mapView.invalidate();
Regard
You don't have to remove specific layer. You can remove an overlay specified by it's reference (e.g. myOverlay).
LocationOverlay myOverlay = new MyLocationOverlay(drawable, myContext); //`you forgot the name of variable`
mapView.getOverlays().remove(myOverlay);

Android: Map of ArrayList's

I use a custom list adapter and ArrayList for my ListView. This solution was good enough but now I need to use Map of ArrayLists, something like this:
TreeMap<String, ArrayList<ItemsModel>>
where ItemsModel is a Java bean. Earlier I used to populate this ArrayList it that way:
itemsDataArrayList.add(itemModel)
Now I faced some difficulties with Map interface. First, I don't know how to populate my new Map structure: I suppose this
mapInstance.put(itemModel.getItemName.toString(), itemsDataArrayList)
won't work because itemsDataArrayList is the list of elements, not a certain element.
Second, I'm not sure how to properly declare this map instance in my ItemsAdapter class. When I was using just ArrayList it was very simple. Some examples would be very helpful.
What I recommend you look into / try is creating your own BaseAdapter. When you override this class it will give you all the functions you need to override to populate the list view.
This has the advantage of giving you complete control of what is put into the listview and how each view is created.
Then after you get it working I recommend looking into the ViewHolder design pattern along with recycling views which is a great way of improving efficiency when scrolling the listview.
What you are really looking for seem to be a MultiMap. To your first Question - your attemp was quite good, you can only put ArrayLists as values into your TreeMap.
The Problem with this might be, that if you want to add some ItemsModel to your Map, you first need to get the List of the key, and then add the ItemsModel to that list. Additionally you need to ensure, that this list for this particular key exist, and if not, create it.
Example:
String key = "hi";
ArrayList keyList = mapInstance.get(key);
if (keyList == null) {
keyList = new ArrayList();
mapInstance.put(key, keyList);
}
keyList.add(itemsModelInstance);
A get()/contains() and so on may be somehow equal. I'd suggest you build your own Multimap<?,?> Implementation or just take an existing one, like the one from Guava (link above).
Kind regards,
avi

ListView / ListAdapter find back the object out of the list

I'm wondering a simple way to find back the object corresponding to the clicked item..
They're tons of examples on the web on how to figure out the ListView setup with the setListAdpater, but much less on how to well handle its listener.
Is "by position" the only way ?? I'm wondering a possibility to associate the objects itselves to the adapter, to not have to use their position in list (or even the displayed String!) to find back the Object referred by the clicked label..
Position is what is used always. The ListView works with using the position.
But if you want to access the ListAdapter and get a value out by providing a string, than you will have to extend ListView and implement that functionality yourself. You can overwrite the different methods that handle adding and removing and keep a HashMap where you keep the string representing the object. Then through a getObject(String key) you return the object that is in the hashmap for that key.

Categories

Resources