Custom Balloons - Toggle Button

380 views Asked by At

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");
            }
        }
    });
}
1

There are 1 answers

0
A Random Android Dev On

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):

    itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(drawable, mapView);

    GeoPoint point = new GeoPoint((int)(51.5174723*1E6),(int)(-0.0899537*1E6));
    CustomOverlayItem overlayItem = new CustomOverlayItem(point, "Tomorrow Never Dies (1997)", 
            "(M gives Bond his mission in Daimler car)", 
            "http://ia.media-imdb.com/images/M/MV5BMTM1MTk2ODQxNV5BMl5BanBnXkFtZTcwOTY5MDg0NA@@._V1._SX40_CR0,0,40,54_.jpg");
    itemizedOverlay.addOverlay(overlayItem);

    //This bottom line is what I'm trying to suggest
    itemizedOverlay2 = new CustomItemizedOverlay<CustomOverlayItem>(drawable, mapView);
    GeoPoint point2 = new GeoPoint((int)(51.515259*1E6),(int)(-0.086623*1E6));
    CustomOverlayItem overlayItem2 = new CustomOverlayItem(point2, "GoldenEye (1995)", 
            "(Interiors Russian defence ministry council chambers in St Petersburg)", 
            "http://ia.media-imdb.com/images/M/MV5BMzk2OTg4MTk1NF5BMl5BanBnXkFtZTcwNjExNTgzNA@@._V1._SX40_CR0,0,40,54_.jpg");       
    itemizedOverlay2.addOverlay(overlayItem2);

    mapOverlays.add(itemizedOverlay);