I'm developing a travel app. On Google map API V2 feature, I want each InfoWindow have an different image.
I've override WindowInfoAdapter for custom title and detail text.
public class MyInfoWindowAdapter implements InfoWindowAdapter {
private final View mView;
public MyInfoWindowAdapter(Activity activity) {
mView = activity.getLayoutInflater().inflate(R.layout.custom_info_window, null);
}
@Override
public View getInfoContents(Marker marker){
String title = marker.getTitle();
final String snippet = marker.getSnippet();
final TextView titleUi = (TextView) mView.findViewById(R.id.title);
// final View subtitleUi = mView.findViewById(R.id.subtitle);
final TextView snippetUi = ((TextView) mView.findViewById(R.id.snippet));
final TextView placeid = ((TextView) mView.findViewById(R.id.placeid));
final RatingBar voteUi = ((RatingBar) mView.findViewById(R.id.ratingBar1));
final ImageView imageUi = ((ImageView) mView.findViewById(R.id.imageView1));
titleUi.setText(title);
//other code
return mView;
}
@Override
public View getInfoWindow(Marker marker){
return null;
}
}
It work fine because It's String.
Now I want to add an image on that InforWindow using ImageView.
The problem appear because I used image from asserts and stream. It's something like this
InputStream ims = getSherlockActivity().getAssets().open("images/" + imageSubPath + "/" + splitedImages[i].toLowerCase());
Drawable iImages = Drawable.createFromStream(ims, null);
I can't put Drawable object to snippet as I did with String before. The result I want here:
How can I display images on InfoWindows, any advices are great!
After three hours of scratching my head I solved this with postDelayed handler. The idea is: object, comtaining data for infoWindow, must have some Drawable field (image, for example). When you first time show infoWindow, some AsyncTash or another async process obtains picture and put it's deawable into image. You must set postDealyed runnable, which will check image value everu X millis and if it became not null, re-show infoWindow, else - set another postDelayed run. My part of getInfoContents code:
Sure, you can return null on first call so your infoWindow will not show until image obtained, but it will cause some lag.
You would have to create additional data structure to hold your images, e.g.:
after you add marker to
GoogleMap
:in
getInfoContents
:and add it to the
ImageView
.Another way would be to use Android Maps Extensions, which has methods like
Marker.setData(Object)
andObject Marker.getData()
. This you can use to directly assignDrawable
to marker, just like you do with snippet.