自定义信息窗口仅显示android中列表的最后一个元素 public void marker1(最终列表名, 最终列表疾病,最终列表列表, 最终列表ListOlderlyImage,列表listArduinomac, List listLat,List listLong){ Log.e(“”,Integer.toString(listName.size()); 对于(int i=0;i
这是我使用的自定义infowindowadapter自定义信息窗口仅显示android中列表的最后一个元素 public void marker1(最终列表名, 最终列表疾病,最终列表列表, 最终列表ListOlderlyImage,列表listArduinomac, List listLat,List listLong){ Log.e(“”,Integer.toString(listName.size()); 对于(int i=0;i,android,google-maps,infowindow,Android,Google Maps,Infowindow,这是我使用的自定义infowindowadapter public void marker1(final List<String> listName, final List<String> listIllness, final List<String> listIC, final List<String> listElderlyimage, List<String> listArduinomac,
public void marker1(final List<String> listName,
final List<String> listIllness, final List<String> listIC,
final List<String> listElderlyimage, List<String> listArduinomac,
List<String> listLat, List<String> listLong) {
Log.e("", Integer.toString(listName.size()));
for (int i = 0; i < listName.size(); i++) {
name = listName.get(i);
ic = listIC.get(i);
illness = listIllness.get(i);
Double Lat = Double.parseDouble(listLat.get(i));
Double Long = Double.parseDouble(listLong.get(i));
MarkerOptions marker = new MarkerOptions().position(new LatLng(Lat,
Long));
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_VIOLET));
infoWindowAdapter = new MarkerInfoWindowAdapter();
googleMap.setInfoWindowAdapter(infoWindowAdapter);
infoWindowAdapter.setName(name);
infoWindowAdapter.setIC(ic);
infoWindowAdapter.setIllness(illness);
googleMap.addMarker(marker);
}// for loop
}// marker1
类MarkerInfoWindowAdapter实现InfoWindowAdapter{
私人观点膨胀观点;
私有字符串名称、ic、疾病;
公共void集合名(字符串名){
this.name=名称;
}
公共无效setIC(字符串ic){
this.ic=ic;
}
公共疾病(字符串疾病){
这个。疾病=疾病;
}
MarkerInfoWindowAdapter(){
充气视图=getActivity().GetLayoutFlater().充气(
R.layout.custom\u info\u contents,空);
}
@凌驾
公共视图getInfoContents(标记器){
setInfo(标记,充气视图);
返回充气视图;
}
@凌驾
公共视图getInfoWindow(标记器){
setInfo(标记,充气视图);
返回充气视图;
}
私有void setInfo(标记、视图){
TextView txtname=(TextView)视图
.findViewById(R.id.txtPatientName);
TextView txtIC=(TextView)view.findViewById(R.id.txtIC);
TextView txtDiseasy=(TextView)view.findViewById(R.id.txtDiseasy);
txtname.setText(名称);
txtIC.setText(ic);
txt疾病。setText(疾病);
Log.e(“,txtname.toString());
}
}
大家好,我不知道为什么每次我点击标记时,它总是显示同一个人的信息。我不确定哪里出了问题。请帮帮我!多谢各位
它不断显示同一个人的信息
这是因为在MarkerInfoWindowAdapter
中只有一个“个人信息”,而忽略传递到getInfoWindow()
中的标记。如果要基于标记填充信息窗口,则需要查找与该标记相关的信息。显示了根据标记查找模型数据
另外,不要同时实现getInfoWindow()
和getInfoContents()
。如果它返回一个非空值,则只使用一个--getInfoWindow()
,否则getInfoContents()
。在这种情况下,由于您总是从getInfoWindow()
返回非null
值,因此将永远不会调用getInfoContents()
另外,不要为每个标记创建InfoWindowAdapter
。仅使用一个InfoWindowAdapter
。在您的情况下,它将是您创建的最后一个标记。那么可以给我一个标记列表吗?并将它们传递到自定义信息窗口?@MarcusKoh:InfoWindowAdapter
需要一种方法,根据提供给getInfoWindow()
或getInfoContents()
的标记找到要显示的详细信息。如何实现这一点取决于您。
class MarkerInfoWindowAdapter implements InfoWindowAdapter {
private View inflatedView;
private String name, ic, illness;
public void setName(String name) {
this.name = name;
}
public void setIC(String ic) {
this.ic = ic;
}
public void setIllness(String illness) {
this.illness = illness;
}
MarkerInfoWindowAdapter() {
inflatedView = getActivity().getLayoutInflater().inflate(
R.layout.custom_info_contents, 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) {
TextView txtname = (TextView) view
.findViewById(R.id.txtPatientName);
TextView txtIC = (TextView) view.findViewById(R.id.txtIC);
TextView txtIllness = (TextView) view.findViewById(R.id.txtIllness);
txtname.setText(name);
txtIC.setText(ic);
txtIllness.setText(illness);
Log.e("<>", txtname.toString());
}
}