Forum Xamarin.Android

MapView with tappable bubbles

SteveWhiteSteveWhite GBMember ✭✭
edited October 2012 in Xamarin.Android

I'm porting over an app from iOS to Android and have some screens with a MapView with a lot of markers. On iOS it's pretty simple to use a custom Annotation View and tap through to a details screen. On Android it ain't so simple, which surprises me.

Does anyone have an example on how to show a small View when tapping a marker? This View needs to contain a string and a button so I can attach an event and load a new Activity passing in some details from the tapped marker.


  • JoeJoe AUMember
    edited October 2012

    I do it something like this:

    public class MyOverlay : ItemizedOverlay
        private readonly List<OverlayItem> _items = new List<OverlayItem>();
        private readonly Action<string> _itemTapCallback;
        public GroupOverlay(Drawable defaultMarker, Action<string> itemTapCallBack)
            : base(BoundCenterBottom(defaultMarker))
            _itemTapCallback = itemTapCallBack;
        protected override bool OnTap(int index)
            if (_itemTapCallback == null) return base.OnTap(index);
            var item = _items[index];
            return true;
        // Fill in the blanks.

    This is a minimal example of course. You have access to things like the item snippet etc, so you could have a callback receiving an object if you wanted to do something more elaborate. Just a matter of how you set up the item list.

    In the callback, just show a dialog/view/whatever.

  • JoeJoe AUMember
    edited October 2012

    I just noticed there's a cut and paste error in the code above. GroupOverlay should be the MyOverlay constructor.

  • Hi,

    I have one with an alert dialog. Try this:

Sign In or Register to comment.