2
我在使用动态内容填充InfoWindows时遇到困难。我有一个ArrayList与数据,我想填充infoWindow。如果我在标记上使用方法代码片段,请动态显示数据,但全部在一行上,所以我不得不使用CustomInfoWindowAdapter。如果我使用CustomInfoWindowAdapter,则为每个InfoWindow显示相同的数据。我错了什么?如何将来自ArrayList的动态数据设置为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中的信息窗口的方法。
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);
}
预先感谢您的帮助