大概講解:
在百度地圖上顯示一個marker,當marker被點擊后,顯示自定義的View.當自定義的View被點擊后,響應不同Button的點擊事件。被百度這個infowindo里面的view坑慘了,一直以為不能點擊呢??原來里面的view可以點擊也可以被響應!!
先看效果圖:
備注:點擊詳情(進入此任務詳情、點擊導航進入百度導航)
代碼如下:
baiduMap.setOnMarkerClickListener(new BaiduMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
LatLng latLng =marker.getPosition();
InfoWindow currentInfoWindow = new InfoWindow(getInfoWindoView(marker,taskJson),latLng, -77);
baiduMap.showInfoWindow(currentInfoWindow);
return true;
}
});
那么Infowindow的自定義View在哪里呢?
private View getInfoWindoView(final Marker marker,final JsonObject taskJson){
if (null == infoView) {
infoView = (ViewGroup) LayoutInflater.from(assignmentsActivity).inflate(R.layout.balloon_overlay, null);
}
tvTitle = (TextView) infoView.findViewById(R.id.balloon_item_title);
tvDetailLocation = (TextView) infoView.findViewById(R.id.balloon_item_snippet);
layout_taskInfo = (LinearLayout) infoView.findViewById(R.id.layout_taskInfo);
iv_navigation = (ImageView) infoView.findViewById(R.id.iv_navigation);
tvTitle.setText(marker.getExtraInfo().getString("title"));
tvDetailLocation.setText(marker.getExtraInfo().getString("subject"));
layout_taskInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Common.switchToTaskDetail(assignmentsActivity, taskJson);
}
});
iv_navigation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
viewInMapApp(marker.getPosition().latitude, marker.getPosition().longitude);
}
});
return infoView;
}

