I'm currently exploring ArcGIS's Android SDK.

However, I've found that when adding a ShapefileFeatureTable to a FeatureLayer:

    FeatureLayer featureLayer = new FeatureLayer(shapefileFeatureTable);
    featureLayer.setRenderer(new SimpleRenderer(new SimpleFillSymbol(

and then trying to remove it:


it doesn't work! (the layer is still visible)

I've tried to change the following:


and this doesn't work either.

EXPLANATORY NOTE: I'm trying to add and remove the feature layer because I want to show a GraphicsLayer on the map, but if I don't load a FeatureLayer first, the MapView stays completely black. I tried to set the SpatialReference and the background grid, but the only thing that worked was adding a bogus FeatureLayer first. I eventually "fixed it" by calling:


But I still think it's suboptimal solution. Any ideas??


Basically, the problem occurred because the layer wasn't added yet when I tried to remove it (the layer addition is an asynchronous process), so you need to add a listener:

    mapView.addLayer( featureLayer );
    mapView.setOnStatusChangedListener( new OnStatusChangedListener() {
        // adding and removing immediately doesn't work
        // you need to wait until the featureLayer is fully added/loaded to be able to remove it
        public void onStatusChanged( Object o, STATUS status ) {
            if ( o == featureLayer ) {
                if ( status == STATUS.LAYER_LOADED ) {
                    mapView.removeLayer( featureLayer );
                    mapView.setOnStatusChangedListener( null );
    } );

I added the setOnStatusChangedListener back to null to not have the callback be run every time the map status changes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.