关于百度地图InfoWindow响应自定义布局点击事件
大概讲解:
在百度地图上显示一个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; }