private void promptForTileSource ( ) { AlertDialog . Builder builderSingle = new AlertDialog . Builder ( getContext ( ) ) ; builderSingle . setIcon ( R . drawable . icon ) ; builderSingle . setTitle ( "Select Offline Tile source:-" ) ; final ArrayAdapter < ITileSource > arrayAdapter = new ArrayAdapter < ITileSource > ( getContext ( ) , android . R . layout . select_dialog_singlechoice ) ; arrayAdapter . addAll ( tileSources ) ; builderSingle . setNegativeButton ( "cancel" , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { dialog . dismiss ( ) ; } } ) ; builderSingle . setAdapter ( arrayAdapter , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { final ITileSource strName = arrayAdapter . getItem ( which ) ; AlertDialog . Builder builderInner = new AlertDialog . Builder ( getContext ( ) ) ; builderInner . setMessage ( strName . name ( ) ) ; builderInner . setTitle ( "Your Selected Item is" ) ; builderInner . setPositiveButton ( "Ok" , new DialogInterface . OnClickListener ( ) { @ Override public void onClick ( DialogInterface dialog , int which ) { mMapView . setTileSource ( strName ) ; //new XYTileSource(strName, 0, 22, 256, "png", new String[0])); //on tile sources that are supported, center the map an area that's within bounds if ( strName instanceof MapsForgeTileSource ) { final MapsForgeTileSource src = ( MapsForgeTileSource ) strName ; mMapView . post ( new Runnable ( ) { @ Override public void run ( ) { mMapView . getController ( ) . setZoom ( src . getMinimumZoomLevel ( ) ) ; mMapView . setMinZoomLevel ( ( double ) src . getMinimumZoomLevel ( ) ) ; mMapView . setMaxZoomLevel ( ( double ) src . getMaximumZoomLevel ( ) ) ; mMapView . invalidate ( ) ; mMapView . zoomToBoundingBox ( src . getBoundsOsmdroid ( ) , true ) ; } } ) ; } else if ( strName instanceof GeopackageRasterTileSource ) { final GeopackageRasterTileSource src = ( GeopackageRasterTileSource ) strName ; mMapView . post ( new Runnable ( ) { @ Override public void run ( ) { mMapView . getController ( ) . setZoom ( src . getMinimumZoomLevel ( ) ) ; mMapView . setMinZoomLevel ( ( double ) src . getMinimumZoomLevel ( ) ) ; mMapView . setMaxZoomLevel ( ( double ) src . getMaximumZoomLevel ( ) ) ; mMapView . invalidate ( ) ; mMapView . zoomToBoundingBox ( src . getBounds ( ) , true ) ; } } ) ; } dialog . dismiss ( ) ; } } ) ; builderInner . show ( ) ; } } ) ; builderSingle . show ( ) ; }
step 3 ask for the tile source