Reputation: 1157
I have a custom "InfoWindow" for a marker, which has buttons, but for default user can't click over the buttons or slide on lists of that layout because that info window is like an image.
Note: the solution in https://stackoverflow.com/a/15040761/2183804 doesn't apply to my problem because different markers has different info Windows (I already tried modifying that answer without success).
So, to solve my problem, I though on putting a layout above the marker when the user clicks over the marker. How can I achieve to put the layout above the marker?
In this example, I have a list with clickable items in the layout
Upvotes: 1
Views: 1057
Reputation: 1157
A solution can be find on this link: https://stackoverflow.com/a/31995000/3957303
The basic idea is to use a PopupWindow
to show the layout on the screen, and then play with its location to potition it over the marker with the updatePopup
method described in the answer. And every time the camera changes (listening to the CameraChangeListener
), you call the updatePopup
method.
Upvotes: 1
Reputation: 3830
I have achieved this by adding a custom info window adapter. And then set it to my map . And in getInfoWindow()
of adapter ,you can write all the click listeners to your views.Here is the code .
private class CustomInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
private View view;
public CustomInfoWindowAdapter() {
view = getLayoutInflater().inflate(R.layout.custom_info_window, null);
}
@Override
public View getInfoContents(Marker marker) {
if (marker != null
&& marker.isInfoWindowShown()) {
marker.hideInfoWindow();
marker.showInfoWindow();
}
return null;
}
@Override
public View getInfoWindow(final Marker marker) {
final ImageView image = ((ImageView) view.findViewById(R.id.badge));
final String title = marker.getTitle();
final TextView titleUi = ((TextView) view.findViewById(R.id.title));
if (title != null) {
titleUi.setText(title);
} else {
titleUi.setText("");
}
return view;
}
}
And set it to map by this
private GoogleMap mMap;
mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());
Hope it helps. Happy coding...
Upvotes: 0