The purpose of this sample is to show how to customize the UI of a pop-up. The layout and style of a pop-up can be changed through XML files and extending some built-in classes of the pop-up API.
- Popup API
- MapViewHelper
This sample shows how to customize the UI of a pop-up and two ways of creating pop-ups. The simplest way is to utilize a helper class from ArcGIS Android Application Tookit called MapViewHelper
to create pop-ups with default UI. The MapViewHelper
class will iterate through and query each layer in the MapView
. A pop-up will be created for each feature in the query result and will be added to a PopupContainer
. The user-defined PopupCreateListener
is called after the pop-ups are created. You can use the logic in the PopupCreateListener
to display the pop-ups.
Another approach is more complicated but more powerful. This approach allows users to customize the UI of a pop-up. In this sample a class called LayerQueryTask
demonstrates this approach. LayerQueryTask
loops through each layer and queries the MapView
in an asynchronous task. The asynchronous task will create pop-ups for the query result. Before a pop-up is created, a new PopupLayoutInfo
will be populated from XML file and be passed to Layer.createPopup()
as a parameter. Then the four basic views such as title, attribute, media and attachment view will be modified by instantiating the sub-classes of the built-in classes of the views. The style of the views then can be customized through these sub-classes and XML files.
Pop-ups will be display in a fragment called PopupFragment
. This fragment also provides menu to edit or delete a feature based on the edit properties of the feature.
The Popup samples depend on the Application Tookit for ArcGIS Android and the Andriod Support Library. Instructions for setting that it up prior to running the app is detailed below.
- Create a new Sample project for PopupUICustomization. Refer to the Integration features document to create a new sample project.
- Right click the sample project and select ArcGIS > Add Application Toolkit to add the tookit to the project
- Right click the sample project and select Android Tools > Add Support Library
- Accept packages to install and click Install
- Under Android Private Libraries you should see the android-support-v4.jar file library
- Right click the sample project and select Properties
- Select the Java Build Path on the left hand side then select Order and Export in the Java Build Path tabs
- Make sure ArcGIS Android Application Toolkit and Android Private Libraries are checked
- Run the application
- Single tap on the map to bring up pop-ups with customized UI. Long press on the map to display pop-ups of default UI for comparison. Tap the Edit button to enter into editing mode to edit attributes, add/delete attachments, delete feature and save edits.