自定义气球 - 切换按钮

时间:2012-08-09 22:22:32

标签: android user-interface popup-balloons

我使用这个漂亮的库来显示气球: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");
            }
        }
    });
}

1 个答案:

答案 0 :(得分:0)

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

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

让我用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);