0

I am implementing google maps in my application. My requirement is to display custom infoWindow when click on marker.

My custom infoWindow contains a listview and i need to perform some operation based on clicked item.

i am getting click event of whole infoWindow (using OnInfoWindowClickListener) but the problem is, i am not getting click event for list view inside infoWindow.

As per description here

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 (for example, 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.

So is there any way by which i can get click event of each clicked item inside custom infoWindow ?

Screenshot : enter image description here

Buddy
  • 105
  • 1
  • 10
  • use custom adapter, inside custom adapter getview method you can add layouts and listview etc .. googleMap.setInfoWindowAdapter(new MyCustomAdapterForItems()); your adapter implements GoogleMap.InfoWindowAdapter like public class MyCustomAdapterForItems implements GoogleMap.InfoWindowAdapter { } – priyanka morisetti Jan 29 '16 at 11:08
  • Still its not working :-( – Buddy Jan 29 '16 at 11:52
  • is there any way to achieve this ? – Buddy Jan 31 '16 at 16:20

1 Answers1

0

The best approach is probably by wrapping the map in layout. Where you will set listener to touch evetns and then propagate the events to saved instance of infowindows View.

See answer: https://stackoverflow.com/a/15040761/838424

This works for buttons, but from unknown reason it does not works for ListView (but clicks into ListView are propagated).

Update: The clicks are not propagated to items because of function isAttachedToWindow returns false (in AbsListView.onTouchEvent). Which blocks processing the click event.

Workaround is to use code in wrapper on dispatchTouchEvent

int pos = myListView.pointToPosition((int)copyEv.getX(), (int)copyEv.getY());

my complete workaround:

if (copyEv.getX() >= 0 && copyEv.getY() >= 0
                && copyEv.getX() < infoWindow.getWidth()
                && copyEv.getY() < infoWindow.getHeight())
        {
            // event is inside infoWindow
            final int actionMasked = ev.getActionMasked();
            switch (actionMasked) {
                case MotionEvent.ACTION_DOWN:
                    int pos = vItems.pointToPosition((int)copyEv.getX(), (int)copyEv.getY());
                    if (pos >= 0) {
                        vItems.performItemClick(infoWindow, pos, 0);
                        ret = true;
                    }
                    break;
                case MotionEvent.ACTION_UP: {
                    break;
                }
            }
        }
Community
  • 1
  • 1
j.edi
  • 67
  • 1
  • 11