2012-08-09 102 views
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"); 
      } 
     } 
    }); 
} 

回答

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/[email protected]@._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/[email protected]@._V1._SX40_CR0,0,40,54_.jpg");  
    itemizedOverlay2.addOverlay(overlayItem2); 

    mapOverlays.add(itemizedOverlay);