0

我使用这个不错的库来显示气球:MapViewBalloons

我想在气球中添加一个切换按钮,这样我就可以将一个点标记为收藏。问题是它会切换整个叠加层的状态,而不仅仅是当前气球的状态。

我该如何解决?这是我的代码,提前谢谢!

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

1 回答 1

0

首先,“它切换整个叠加层的状态,而不仅仅是当前气球的状态”是什么意思?你指的是什么状态。

无论您对切换状态的定义如何,我都建议这样做:尝试为每个叠加层使用单独的 ItemizedOverlay,而不是将多个叠加层添加到同一个气球。我遇到了一个类似的问题,即我的整个叠加层都受到了影响,而不是当前的气球,这样做解决了这个问题。

让我展示一下我试图使用来自 mapviewballoons 的代码(custommap 活动)的建议:

    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);
于 2012-08-09T23:57:14.990 回答