I use this nice library for showing balloons: MapViewBalloons
I want to add a toggle button into the baloon, so I can mark a point as a favorite. The problem is it switches the state of the whole overlay, not only of the current balloon.
How do I fix this? Here is my code, thanks in advance!
@Override
protected void setupView(Context context, final ViewGroup parent) {
// inflate our custom layout into parent
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.baloon_overlay, parent);
ToggleButton favorite = (ToggleButton) v
.findViewById(R.id.toggleButton1);
favorite.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (isFav==false) {
isFav=true;
System.out.println("true");}
else {
isFav=false;
System.out.println("false");
}
}
});
}
Firstly, what do you mean by "it switches the state of the whole overlay, not only of the current balloon"? What state are you referring to.
Irrespective of your definition of switching the state I'd suggest this: try using a separate ItemizedOverlay for each of your overlays instead of adding multiple overlays to the same balloon. I'd faced a similar issue whereby my entire overlay was being affected instead of the current balloon and doing so solved the issue.
Let me show what I'm trying to suggest using the code from mapviewballoons (custommap activity):