AnsweredAssumed Answered

help with displaying popups on map features in app?

Question asked by coracoleman14 on Oct 23, 2017
Latest reply on Feb 3, 2018 by springoff

Below is my current implementation of this method for displaying popups from the latest ArcGIS Runtime for Android SDK, however I have come to a stopping point where you see below:

 showPopup(identifiedPopup, screenPoint); 

While I have been able to print out popups to the logcat console, I am still unsure how to go about actually configuring their display in my app past this info? I am getting a bit confused looking at the API code for popups here, and am wondering if I need to use the methods mentioned there in order to do this after I grab the popup from my layer? 

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;

import com.esri.arcgisruntime.concurrent.ListenableFuture;
import com.esri.arcgisruntime.layers.FeatureLayer;
import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.GeoElement;
import com.esri.arcgisruntime.mapping.popup.Popup;
import com.esri.arcgisruntime.mapping.view.DefaultMapViewOnTouchListener;
import com.esri.arcgisruntime.mapping.view.IdentifyLayerResult;
import com.esri.arcgisruntime.mapping.view.MapView;
import com.esri.arcgisruntime.portal.Portal;
import com.esri.arcgisruntime.portal.PortalItem;

import java.util.List;
import java.util.concurrent.ExecutionException;

import static;

public class MainActivity extends AppCompatActivity {

    private Portal aPortal;
    private PortalItem aPortalItem;
    private ArcGISMap aMap;
    private MapView aMapView;

    protected void onCreate(Bundle savedInstanceState) {

        // inflate MapView from layout
        aMapView = (MapView) findViewById(mapView);

        // get the portal url for ArcGIS Online
        aPortal = new Portal(getResources().getString(R.string.portal_url));
        // get the pre-defined portal id and portal url
        aPortalItem = new PortalItem(aPortal, getResources().getString(R.string.webmap_glacier_national_park_id));
        // create a map from a PortalItem
        aMap = new ArcGISMap(aPortalItem);
        // set the map to be displayed in this view
        Log.d("MAP SET", "we have set our map!");

        aMapView.setOnTouchListener(new IdentifyFeatureLayerTouchListener(this, aMapView));
        Log.d("ID SET", "we have set our map to be identified!");


class IdentifyFeatureLayerTouchListener extends DefaultMapViewOnTouchListener {

    // provide a default constructor
    public IdentifyFeatureLayerTouchListener(Context context, MapView mapView) {
        super(context, mapView);

    // override the onSingleTapConfirmed gesture to handle a single tap on the MapView
    public boolean onSingleTapConfirmed(MotionEvent e) {

        // reference to the layer to identify features in
        FeatureLayer layer = null;

        // get the screen point where user tapped
        final screenPoint = new e.getX(), (int) e.getY());
        // call identifyLayersAsync, passing in the screen point, tolerance, return types, and maximum results, but no layer
        final ListenableFuture<List<IdentifyLayerResult>> identifyFuture = mMapView.identifyLayersAsync(
                screenPoint, 10, false);

        // add a listener to the future
        identifyFuture.addDoneListener(new Runnable() {

            public void run() {
                try {

                    // get the identify results from the future - returns when the operation is complete
                    List<IdentifyLayerResult> identifyLayersResults = identifyFuture.get();

                    // Here we just show the pop-up for the first (top) layer; if more than one layer may have pop-ups, or more
                    // than one element is identified in a single layer, add controls to the pop-up content to iterate through
                    // multiple pop-ups.
                    if (identifyLayersResults.size() >= 1) {
                        IdentifyLayerResult identifyLayerResult = identifyLayersResults.get(0);

                        // Only identifying the topmost item in this example, so only expecting one pop-up
                        if (identifyLayerResult.getPopups().size() >= 1) {
                            Popup identifiedPopup = identifyLayerResult.getPopups().get(0);

                            showPopup(identifiedPopup, screenPoint);
                            Log.d("popup", identifiedPopup.toString());


                } catch (InterruptedException | ExecutionException ex) {
                    // deal with exceptions thrown from the async identify operation

        return true;