Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
自定义信息窗口仅显示android中列表的最后一个元素 public void marker1(最终列表名, 最终列表疾病,最终列表列表, 最终列表ListOlderlyImage,列表listArduinomac, List listLat,List listLong){ Log.e(“”,Integer.toString(listName.size()); 对于(int i=0;i_Android_Google Maps_Infowindow - Fatal编程技术网

自定义信息窗口仅显示android中列表的最后一个元素 public void marker1(最终列表名, 最终列表疾病,最终列表列表, 最终列表ListOlderlyImage,列表listArduinomac, List listLat,List listLong){ Log.e(“”,Integer.toString(listName.size()); 对于(int i=0;i

自定义信息窗口仅显示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,

这是我使用的自定义infowindowadapter

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());
    }
}