Android application structure question
I am currently working on an application that makes use of a MapView and adds overlays to it. Basically at anyone one given time the overlay list should never exceed two.
Heres what I have tried to do...
I have extended the ItemizedOverlay class (MyFriendOverlay) and then created a private ArrayList object inside that extended class that I would attach the overlays to. However; I have come across a problem that I am unsure how to fix. If you look at this segment of code:
ImageView mapMarker = new ImageView(getApplicationContext());
mapMarker.setImageResource(R.drawable.markertrp);
myPointsToShow = new myFriendOverlay(mapMarker.getDrawable(), getApplicationContext());
As can be noted here I am created a ImageView with an icon based on my drawables. After this I have my extended class from ItemizedOverlay. In the constructor it takes two parameter the drawable and the context.
From what I know the constructor below is required (perhaps it can be modified):
public myFriendOverlay(Drawable defaultMarker, Context context)
Problem here is that I keep creating a new instance of myPoints开发者_运维百科ToShow, which is a problem because I have a ArrayList that I want to use in the extended class so I have direct control over the overlays. And by instantiating a new one every time, I don't really add to the list itself.
In short:
All I want is for my application to have two points (A and B) where if a new location is detected for say B, then remove B from the overlay list, and replace it with the new location. And the same for A as well. In order to simplify it, I want to attach index 0 to A and index 1 to B, so that it doesn't span over two points.
I am unable to come up with a solution for this because of the problem of the necessary constructor, perhaps I'm thinking too hard about it...
Please offer any feedback! :)
Thanks for reading.
From my experience what I do is the following:
- Create an item overlay per type of image I am going to show.
- If the list of items per overlay is not very long I pass it inside an intent.
Btw you need to use R.drawable.something
for your overlay. You don't need to create an ImageView
.
I have been using this android-library for maps: android-mapviewballoons. Check it out!
精彩评论