Skip to content Skip to sidebar Skip to footer

Add Android Fragment To Infowindow Contents

I'm writing an Android application that targets 4.0 and up and I'm using Google Maps v2. I'd like to set the contents of an InfoWindow with a Fragment. Does anyone know if it's pos

Solution 1:

The view returned from adapter is not a live view, but is transformed into a bitmap, so no code associated with this view (like button clicks) will ever execute.

The same case would be for fragments, so you may stop trying that and instead create a layout that binds together map_details and fragment layout. A use of include in xml will probably work.

Solution 2:

I've not seen anyone achieve it and I don't think it is possible as it's a simple view that is created for you, meaning a lot happens behind your back.

Solution 3:

Three suggestions:

  1. The transaction and the commit is asynchronous. You could try calling http://developer.android.com/reference/android/app/FragmentManager.html#executePendingTransactions(). However, I got exceptions at one point when I tried to use that. But you might have more luck with it.

  2. Otherwise, you could try adding the fragment as regular subview to your container by replacing R.id.fragment_map_details with the view returned from frag.getView(). That's just a wild guess, however. Maybe you're not supposed to make use of that return value in that way. (I've gotten a bit cautious when it comes to Android's API...)

  3. From https://developers.google.com/maps/documentation/android/infowindows (under "Custom info windows"):

To update the info window later (for example, after an image has loaded), call showInfoWindow().

So, if you can find a way to get notified when the fragment transaction is complete then you could call that method to update the info window.

Post a Comment for "Add Android Fragment To Infowindow Contents"