I have a InfoWindowAdapter class in my Android app that refers to an xml layout containing three TextViews. I add a new marker using the code below within an addMarker()
method:
mapView.addMarker(new MarkerOptions()
.position(latLon)
.title(titleText)
.snippet(snippetText)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_green)));
mapView.setInfoWindowAdapter(new InfoWindow(getLayoutInflater()));
mapView.setOnInfoWindowClickListener(this);
I then set the text of my two infowindow textviews using marker.getTitle()
and marker.getSnippet()
within a getInfoContents()
method:
@Override
public View getInfoContents(Marker marker) {
if (popup == null) {
popup = inflater.inflate(R.layout.infowindow_popup, null);
}
TextView tvTitle = (TextView) popup.findViewById(R.id.title);
tvTitle.setText(marker.getTitle());
TextView tvSnippet = (TextView) popup.findViewById(R.id.snippet) ;
tvSnippet.setText(marker.getSnippet());
TextView tvSnippet2 = (TextView) popup.findViewById(R.id.snippet_2) ;
tvSnippet2.setText("test");
return popup;
}
This is all good for the first two textviews but what I would like to know is what is the correct way for me to pass a third string to infoWindowContents()
to use with tvSnippet2
? Obviously I can't use .title()
/.snippet()
and marker.getTitle()
/marker.getSnippet()
because these are already used and would repeat the data.
infoWindowAdapter:
public class InfoWindow implements InfoWindowAdapter {
private View popup = null;
private LayoutInflater inflater = null;
String str;
InfoWindow(LayoutInflater inflater, String s) {
this.inflater = inflater;
str = s;
}
@Override
public View getInfoContents(Marker marker) {
if (popup == null) {
popup = inflater.inflate(R.layout.infowindow_popup, null);
}
TextView tvTitle = (TextView) popup.findViewById(R.id.title);
tvTitle.setText(marker.getTitle());
TextView tvSnippet = (TextView) popup.findViewById(R.id.snippet) ;
tvSnippet.setText(marker.getSnippet());
TextView tvSnippet2 = (TextView) popup.findViewById(R.id.snippet_2) ;
tvSnippet2.setText(str);
return popup;
}
@Override
public View getInfoWindow(Marker marker) {
return null;
}
}