Reputation: 11
I am trying to display an image inside the custom info window, I have 20 custom info windows the use the same layout but when run the code they all appear exactly the same because they all use the same TextView.
map.setInfoWindowAdapter(new InfoWindowAdapter(){
@Override
public View getInfoContents(Marker arg0) {
View v = getLayoutInflater().inflate(R.layout.custommarker, null);
LinearLayout ll = (LinearLayout)findViewById(R.id.ll);
TextView tv = new TextView(this);
tv.setText("Text");
ll.addView(tv);
return v;
}
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
});
Might I be able to display images in default info windows? If not how would I have all of my Custom marker using this layout,
thanks
Upvotes: 0
Views: 1399
Reputation: 47807
Here i saw you one demo how to implement Custom Info Window
.
First of all add one Marker
to Google Map
like:
static final LatLng MELBOURNE = new LatLng(-37.81319, 144.96298);
Marker melbourne = mMap.addMarker(new MarkerOptions()
.position(MELBOURNE)
.title("Melbourne")
.snippet("Population: 4,137,400"));
Now, When you click the Marker
then Custom Info Window
trigger and you'll get particular Marker Title using getTitle()
and Marker snippet using getSnippet()
like:
map.setInfoWindowAdapter(new InfoWindowAdapter(){
@Override
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.custommarker, null);
LinearLayout ll = (LinearLayout)findViewById(R.id.ll);
TextView title = new TextView(this);
title.setText(marker.getTitle());
ll.addView(title);
TextView snipp = new TextView(this);
snipp.setText(marker.getSnippet());
ll.addView(snipp);
return v;
}
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
});
Output: When you click into Marker
then Custom Info Window
display like:
Update: your app getting crash it's becoz of this
LinearLayout ll = (LinearLayout)findViewById(R.id.ll);
Change to
LinearLayout ll = (LinearLayout)v.findViewById(R.id.ll);
your LinearLayout
coming from inflated layout.
Upvotes: 1
Reputation: 11
I used the code
MarkerOptions MarkerT = new MarkerOptions().snippet("Hello");
MarkerT.title(postc.getAuthor());
MarkerT.position(new LatLng(postc.getLat(), postc.getLong()));
MarkerT.icon(BitmapDescriptorFactory.fromBitmap(bmp));
Marker marker = map.addMarker(MarkerT);
map.setInfoWindowAdapter(new InfoWindowAdapter(){
@Override
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.custommarker, null);
LinearLayout ll = (LinearLayout)findViewById(R.id.ll);
ink(marker.getSnippet(),ll);
return v;
}
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
});
This causes a crash and I'm unsure why, Thanks for the reply:) ink = method that creates a textView.
Upvotes: 0