我用这个漂亮的库来显示气球: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");
}
}
});
}
首先,"它切换整个覆盖层的状态,而不仅仅是当前气球的状态"是什么意思?你指的是什么状态。
无论您对切换状态的定义如何,我都建议这样做:尝试为每个叠加层使用单独的逐项叠加层,而不是向同一个气球添加多个叠加层。我遇到了类似的问题,即我的整个覆盖层受到影响,而不是当前的气球,这样做解决了这个问题。
让我展示一下我试图使用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);