【发布时间】:2014-12-12 02:17:40
【问题描述】:
我在使用动态内容填充 InfoWindows 时遇到了困难。我有一个 ArrayList,其中包含我想填充 infoWindow 的数据。如果我在标记上使用方法 sn-p,动态显示数据,但全部显示在一行上,所以我不得不使用 CustomInfoWindowAdapter。如果我使用我的 CustomInfoWindowAdapter,我会为每个 InfoWindow 显示相同的数据。我哪里错了?
这是我的 CustomInfoWindowAdapter:
class MarkerInfoWindowAdapter implements InfoWindowAdapter {
private View inflatedView;
private View tempView;
private String title, description;
public void setTitle(String title) {
this.title = title;
}
public void setDescription(String description) {
this.description = description;
}
MarkerInfoWindowAdapter() {
inflatedView = getLayoutInflater().inflate(R.layout.info_window_layout, null);
// tempView = getLayoutInflater().inflate(R.layout.location_content_window, null);
}
@Override
public View getInfoContents(Marker marker) {
// setInfo(marker, inflatedView);
return inflatedView;
}
@Override
public View getInfoWindow(Marker marker) {
setInfo(marker, inflatedView);
return inflatedView;
}
private void setInfo(Marker marker, View view) {
final TextView txtTitle = (TextView) view.findViewById(R.id.title);
final TextView txtDescription = (TextView) view.findViewById(R.id.lat_lng);
txtTitle.setText(title);
txtDescription.setText(description);
}
}
这是我从 ArrayList 创建 Marker 和 InfoWindow 的方法。
public void drawRoute(HashMap<String, ArrayList<HashMap<String, String>>> result, String type) {
ArrayList<HashMap<String, String>> voyageplan = result.get("optimal");
HashMap<String, String> waypoint1;
for (int i = 0; i < voyageplan.size(); i++) {
waypoint1 = voyageplan.get(i);
googleMap.addMarker(new MarkerOptions().position(position)
.title("WP# "+waypoint1.get("WP").toString()+" (optimal)")
.snippet("prova")
.anchor(0.5f, 0.5f).draggable(false)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA)));
infoWindowAdapter = new MarkerInfoWindowAdapter();
infoWindowAdapter.setTitle(voyageplan.get(i).get("WP"));
infoWindowAdapter.setDescription(voyageplan.get(i).get("lat"));
googleMap.setInfoWindowAdapter(infoWindowAdapter);
}
提前感谢您的帮助
【问题讨论】:
标签: android arraylist google-maps-android-api-2 infowindow