Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button onclicklistener on infowindow in google map

How can i detect the button setOnClickListener in info window on google map? Actually in my info window i have a button and i want to click on that button. Is this possible to do this?

like image 839
Ankit Sharma Avatar asked Nov 29 '13 10:11

Ankit Sharma


2 Answers

Try it

mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {

        }
    });
like image 116
Ba Tới Xì Cơ Avatar answered Oct 20 '22 15:10

Ba Tới Xì Cơ


Actually it not posiable, Google Map renders the content of you custom InfoWindow into an image and displays it to you as an Image. Therefore you set a click Listener only to the whole window and not to the Views inside it.

Your only choice it to set the ClickListener to the whole InfoWindow and popup an Dialog with clickable content you want, and not do it directly inside the InfoWindow.

From Google Docs: https://developers.google.com/maps/documentation/android/marker#info_windows

Note: The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas)) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (e.g., after an image has loaded), call showInfoWindow(). Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.

like image 30
Emil Adz Avatar answered Oct 20 '22 17:10

Emil Adz