Search code examples
javaandroiddialogandroid-mapviewitemizedoverlay

How to create a custom dialog for a itemized overlay item?


So at the moment when i click an itemized overlay item , i just display a simple dialog, i would like to create something more in the lines of the below

On tap dialog

How would i go about doing this for the android phone>?


Solution

  • When you override ItemizedOverlay there is protected onTap method. It has item index as parameter. You should override onTap and use this index to get correct data object. E.g:

    @Override
    protected boolean onTap(int index) {
        getItem(index); \\your overlay item
        return true;
    }
    

    Then you should create custom dialog from code or inflate xml layout, use correct layout params to add it on your MapView:

    MapView.LayoutParams params = new MapView.LayoutParams(LayoutParams.WRAP_CONTENT,     
        LayoutParams.WRAP_CONTENT, point, 0, 0, MapView.LayoutParams.BOTTOM_CENTER);
        params.mode = MapView.LayoutParams.MODE_MAP;            
        MV.addView(popup, params);
    

    MV - your MapView instance; point - your Overlay item GeoPoint; popup - your custom dialog view.