【问题标题】:Why is my InfowindowAdapter data is not changing?为什么我的 InfowindowAdapter 数据没有改变?
【发布时间】:2018-01-25 09:32:36
【问题描述】:

我正在调用 createMarker,它会在循环运行后动态添加数据。我正在使用 InfoWindowAdapter 添加标记选项。但是我有问题,当我单击带有 infoContent 的标记时它不会改变。

这是我添加标记选项的方法..

public MarkerOptions createMarker(final String Date, final String Time, final String Location, final String Engine,final String Remarks, Double latitude, final Double longitude, final String Plate_num) {

        System.out.println(Location + " lLocation");

        mMapFragment.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
            @Override
            public View getInfoWindow(Marker marker) {
                return null;
            }

            @Override
            public View getInfoContents(Marker marker) {
                View v = getActivity().getLayoutInflater().inflate(R.layout.custom_info_contents_vehicle_map, null);
                TextView plate_nu = (TextView) v.findViewById(R.id.plate_num);
                TextView dat = (TextView) v.findViewById(R.id.date);
                TextView tim = (TextView) v.findViewById(R.id.time);
                TextView loc = (TextView) v.findViewById(R.id.location);
                TextView engin = (TextView) v.findViewById(engine);
                TextView remark = (TextView) v.findViewById(R.id.rema);
                plate_nu.setText(Plate_num);
                dat.setText(Date);
                tim.setText(Time);
                loc.setText(Location);
                engin.setText(Engine);
                remark.setText(Remarks);
                return v;
            }
        });

        return new MarkerOptions()
                .position(new LatLng(latitude, longitude))
                .title("Plate No.")
                .snippet(Plate_num)       
                .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
    }

我正在使用系统输出来输出位置,它确实发生了变化。但是,问题所在的信息内容内部。我没有看到任何更改,或者如何使用上面的代码更改我的InfoWindowAdapter 数据??

【问题讨论】:

  • 试试这个 // 从片段中获取 GoogleMap 对象 googleMap = mapFragment.getMap(); // 为谷歌地图设置自定义信息窗口适配器 googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {

标签: android google-maps-markers infowindow


【解决方案1】:

当您单击标记时,首先隐藏您的信息窗口并在您的工作完成后更改信息窗口的内容,然后在显示信息窗口后。我将对您的代码进行更改,请您也这样做。

mMapFragment.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

            @Override
            public boolean onMarkerClick(final Marker marker) {

                marker.hideInfoWindow();

                vm = new VehicleMap();
                vm.setPlate_num(marker.getSnippet());

                latitudeG = marker.getPosition().latitude;
                longitudeG = marker.getPosition().longitude;

                marker.showInfoWindow();

                BottomSheetDialogFragment bottomSheetDialogFragment = new BottomSheetModalMapFragment(activity);
                bottomSheetDialogFragment.show(getFragmentManager(), bottomSheetDialogFragment.getTag());

                return true;
            }
        });

【讨论】:

  • 嗨,Kishan,我没有脱衣舞
  • 我希望我的 getInfoContents textview 根据我设置的变量动态更改
  • 您能否针对此问题进行更多解释,因为可能无法满足您的要求?
  • 我的InfoWindowAdapter中没有收到不同的值
【解决方案2】:

您不能简单地使用循环添加适配器。它不是那样工作的。 您只能像任何其他适配器一样设置一个信息适配器。 所以没有意义的动态 FINAL 值。 您需要将标签设置为标记 并且根据标签值,您需要检索您的值并将其更新为在信息窗口中膨胀的自定义布局。

查看我的blog 了解更多信息

查看类似的SO Answer,其中使用getInfoContents 方法中的标记实例更新值

【讨论】:

    猜你喜欢
    • 2018-11-21
    • 1970-01-01
    • 2016-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-13
    • 2019-01-06
    • 2021-10-31
    相关资源
    最近更新 更多