'Android: Bing Maps API - how to handle Pushpin click?

I have

MapView map = new MapView(this, MapRenderMode.VECTOR); 
MapIcon pushpin = new MapIcon();
MapElementLayer mPinLayer = new MapElementLayer();

mPinLayer.getElements().add(pushpin);
map.getLayers().add(mPinLayer);

and I need to execute this:

Microsoft.Maps.Events.addHandler(pushpin, 'click', function () {});

but in Android Java, not JS



Solution 1:[1]

Found workaround.

mMapView.addOnMapTappedListener(new OnMapTappedListener() {
        @Override
        public boolean onMapTapped(MapTappedEventArgs mapTappedEventArgs) {
            Point position = mapTappedEventArgs.position;
            LinkedList<MapElement> elements = mMapView.findMapElementsAtOffset(position);

            for (MapElement mapElement: elements)
            {
                if (mapElement instanceof MapIcon) {
                    MapIcon mapIcon = (MapIcon) mapElement;
                     // Do your thing. For example set fly out visibility.
                     // mapIcon.setIsFlyoutVisible(!mapIcon.getIsFlyoutVisible());
                }
            }

            return false;
        }
    });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user255936