0

I am calling createMarker that adds data dynamically once run on loop. I am using InfoWindowAdapter to add marker options. However I have problem, it doesn't change when I click the marker with infoContent.

Here's how I add a marker options..

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

I am using system out to output location and it does change. However, inside infocontents where the problem is residing. I am not seeing any changes or how do I make my InfoWindowAdapter change data using code above??

Kaushik
  • 6,150
  • 5
  • 39
  • 54
  • https://mobikul.com/android-setting-custom-info-window-google-map-marker/ – Shubham AgaRwal Aug 17 '17 at 06:49
  • try this // Getting GoogleMap object from the fragment googleMap = mapFragment.getMap(); // Setting a custom info window adapter for the google map googleMap.setInfoWindowAdapter(new InfoWindowAdapter() { – Shubham AgaRwal Aug 17 '17 at 07:30

2 Answers2

0

When you click on the marker that time first makes hide your info window and change content of the info window after once your work done then after showing info window. I will make a change into your code please do same.

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 Donga
  • 2,851
  • 2
  • 23
  • 35
0

You cannot simply add adapter using a loop. It does not work like that. You can only set one info adapter just like any other adapter. So no point of dynamic FINAL values. You need to set the tag to marker and on the basis of tag value, you need to retrieve your values and update the same to the custom layout inflated in the info window.

see my blog for more information

See similar SO Answer where values are updated using marker instance in getInfoContents method

Shubham AgaRwal
  • 4,355
  • 8
  • 41
  • 62