info window android studio repeated last marker

1

I'm just learning and I'm doing an app in android studio where a map with different markers should come out, and each one should display an infowindow with different information (text and image) .. but for some error of mine only shows me the last infowindow configured repeated in all the markers that I add, it is as if over writing the info. the markers I have added them in the following way in the CajerosCer class ..

  Marker marker1 = mMap.addMarker(new MarkerOptions().position(new LatLng(-33.42218, -70.6105))
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.debitrojo1)));
    Cajero c1 = new Cajero("Banco 1", "Activo", "", "direccion 1", "9:00 a 23:00", R.drawable.debitrojo1);
    mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter(LayoutInflater.from(this), c1));

    Marker marker2 = mMap.addMarker(new MarkerOptions().position(new LatLng(-33.415316, -70.540559))
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.debitverde1)));
    Cajero c2 = new Cajero("Banco 2", "Inactivo", "", "direccion 2", "9:00 a 23:00", R.drawable.debitverde1);
    mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter(LayoutInflater.from(this), c2));

    Marker marker3 = mMap.addMarker(new MarkerOptions().position(new LatLng(-33.431447, -70.609332))
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.debitverde1)));
    Cajero c3 = new Cajero("Banco 3", "Inactivo", "", "direccion 3", "9:00 a 23:00", R.drawable.verde1);
    mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter(LayoutInflater.from(this), c3));

    Marker marker4 = mMap.addMarker(new MarkerOptions().position(new LatLng(-40.573886, -73.136952))
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.debitverde1)));
    Cajero c4 = new Cajero("Banco 4", "Activo", "", "direccion 4", "9:00 a 23:00", R.drawable.verde1);
    mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter(LayoutInflater.from(this), c4));

    Marker marker5 = mMap.addMarker(new MarkerOptions().position(new LatLng(-40.574308, -73.15902))
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.debitverde1)));
    Cajero c5 = new Cajero("Banco 5", "Activo", "", "direccion 5","9:00 a 23:00", R.drawable.verde1);
    mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter(LayoutInflater.from(this), c5));

    Marker marker6 = mMap.addMarker(new MarkerOptions().position(new LatLng(-40.578722, -73.174982))
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.debitverde1)));
    Cajero c6 = new Cajero("Sucursal 6", "INACTIVO", "SIN INFORMACION", "direccion 6", "9:00 a 14:00", drawable.rojo1);
    mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter(LayoutInflater.from(this), c6));


    Marker marker7 = mMap.addMarker(new MarkerOptions().position(new LatLng(-40.578722, -74.174982))
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.debitverde1)));
    Cajero c7 = new Cajero("Sucursal 7", "ACTIVO", "SIN INFORMACION", "direccion 7", "9:00 a 14:00", drawable.rojo1);
    mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter(LayoutInflater.from(this), c7));


}

I also have the CustomInfoWindowAdapter class     class CustomInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {

private static final String TAG = "CustomInfoWindowAdapter";
private LayoutInflater inflater;
private Cajero c;

public CustomInfoWindowAdapter(LayoutInflater inflater, Cajero c){
    this.inflater = inflater;
    this.c = c;
}

@Override
public View getInfoWindow(final Marker marker) {

    View infoWindows = inflater.inflate(R.layout.activity_custom_info_window_adapter, null);
    ImageView img = (ImageView) infoWindows.findViewById(R.id.info_window_imagen1);
    img.setImageResource(c.getLayout());
    ((TextView) infoWindows.findViewById(R.id.info_window_nombre)).setText("Cajero " + c.getNombre());
    ((TextView) infoWindows.findViewById(R.id.info_window_estado)).setText("Estado: " + c.getEstado());
    ((TextView) infoWindows.findViewById(R.id.info_window_saldo)).setText("Saldo: " + c.getSaldo());
    ((TextView) infoWindows.findViewById(R.id.info_window_ubicacion)).setText("Direccion: " + c.getDireccion());
    ((TextView) infoWindows.findViewById(R.id.info_window_horario)).setText("Horario: " + c.getHorario());
    return infoWindows;
}
@Override
public View getInfoContents(Marker marker) {
    return null;

}

AYUDAAA :( !! I do not know what I'm doing wrong.

    
asked by Pau 02.05.2018 в 02:21
source

1 answer

0

You have to assign the title and the snippet to your code. In your info windows xml you can have several views as in your case: Cashier, State, Balance ... but remember that the Adapter only gets the title and the snippet .

In your case I recommend that you concatenate for example cashier and state in title and the rest in the snippet within onMapReady and the separations ( split ) within getInfoWindow . The getInfoWindow method is to customize the info window.

@Override
public void onMapReady(GoogleMap googleMap) {
    final CustomInfoWindowAdapter adapter = new CustomInfoWindowAdapter();
    mMap = googleMap;
    float zoomLevel = 13;
    mMap.setInfoWindowAdapter(adapter);

    // concatenas usando "-" :
    String c1 = "Banco 1"+"-"+"Activo"+"-"+" "+"-"+"direccion 1"+"-"+"9:00 a 23:00"+"-"+"R.drawable.debitrojo1";
    mMap.addMarker(new MarkerOptions().position(new LatLng(25.6724958, -100.2614327))
            .title(c1)   // en este caso solo use title
            //.snippet(otro string)
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.debitrojo1)));
    String c2 = ....
}

private class CustomInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
    @Override
    public View getInfoWindow(Marker marker) {
       View infoWindows = inflater.inflate(R.layout.activity_custom_info_window_adapter, null);
       ImageView img = (ImageView) infoWindows.findViewById(R.id.info_window_imagen1);

        // obtienes el String title y lo separas con split, son 6 items, el primero empieza en cero:
        String str = marker.getTitle();
        final String[] str2 = str.split("-"); 

        // cada uno se esos items le asignas un string y lo seteas a las vistas:
        String sNombre = str2[0];
        String sEstado = str2[1];
         .....
((TextView) infoWindows.findViewById(R.id.info_window_nombre)).setText(sNombre);
((TextView) infoWindows.findViewById(R.id.info_window_nombre)).setTextColor(BLUE);
((TextView) infoWindows.findViewById(R.id.info_window_estado)).setText(sEstado);
 ....
return infoWindows;
}

@Override
public View getInfoContents(Marker marker) {
return null;

}

The ideal would be to use a database for the persistence of data and more will be updated.

    
answered by 17.06.2018 в 06:46