Attribute Editing
The purpose of this sample is to demonstrate how to view and edit the attributes of a map layer provided from an ArcGIS Server Feature Layer (exposed from within a FeatureServer service). It also uses a MapServer service of the same data and a cached tiled map service from ArcGIS.com as a basemap. Users can click a feature on the map to view the attributes in a dialog. If the fields are editable then a user can change the attributes of the field. Validation of the field type provides the user with different ways of adding attributes; number fields do not allow text input, date fields provide a date picker dialog, and fields which are used for defining a subtype provide drop down lists. Once attributes have been changed they can be posted to the Feature Layer in an edit operation.
Sample Design:
The most important classes in the sample are the classes which extend Activity (AttributeEditorActivity) and BaseAdapter (AttributeListAdapter).
The AttributeEditorActivity initializes the MapView and ArcGISFeatureLayer objects with the appropriate onStatusChangedListener and onClickListener. The Activity also contains the logic to launch the attributes dialog and apply edits once the user has finished changing the attributes.
The AttributeListAdapter class contains the logic to use information from the feature layer and the feature returned from the on click query to build the attribute dialog. This includes parsing the field, subtype and graphic attributes to build up some additional POJO (plain old java objects) classes to store this information for retrieval when the list is built and for applying the edits. The dialog is constructed from a ListView, each row in the ListView is built from other View elements depending on the field type.
The Feature Layer is added to the map as an ArcGISFeatureLayer in Selection Mode and is backed by an ArcGISDynamicMapServiceLayer based on the exact data. Clicking the map performs a query on the Feature Layer and returns the first feature found and places its attributes into the Dialog. Changes in attribute values are detected from the Dialog and if changes are found they are applied to the server using an apply edits operation on the Feature Service. If an edit has been performed on the subtype field, the underlying ArcGISDynamicMapServiceLayer is also refreshed to show any renderering changes of the edited features (in this example the subtype field is that which is associated with feature renderering). This approach ensures that the minimum amount of data is passed over the network and is therefore suitable for mobile access using a 3G network. This is due to the often smaller size and quicker display of images returned from an ArcGISDynamicMapServiceLayer than the feature information returned for the same extent for an ArcGISFeatureLayer (where the JSON response from the server has to be parsed and each feature drawn).
How to use sample?
1. Launch the sample in emulator or device.
2. Click on the map to highlight a feature and view its attributes in a dialog.
3. Edit the attributes of the Feature. Notice how decimal fields don't allow alphanumeric characters but do allow dots (.) and minus signs (-) in the right place, text fields allow all characters, date fields provide a Date Picker dialog and Type fields display a list of available types.
4. Choose to apply the changes you have made to the server or discard the changes.
5. If you have changed the subtype of the feature, the underlying map service will be redrawn and the symbology of the feature you have edited will be updated to the appropriate renderer.