AnsweredAssumed Answered

How to add feature layer into fragment?

Question asked by giangnguyen101288 on Jul 3, 2015
Latest reply on Aug 10, 2015 by ebader-esristaff

I just add successful a tilesmapserviceslayer and a feature layer into activity. However, when i do this in fragment, it can't work.

Here is my code:

package com.niit.giangnguyen.tree_manager;

 

import android.app.Fragment;

import android.graphics.Color;

import android.os.Bundle;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import com.esri.android.map.MapView;

import com.esri.android.map.ags.ArcGISFeatureLayer;

import com.esri.android.map.ags.ArcGISTiledMapServiceLayer;

import com.esri.core.geometry.Envelope;

 

public class HomeFragment extends Fragment {

    public MapView mv = null;

    public HomeFragment(){}

    @Override

    public View onCreateView(LayoutInflater inflater, ViewGroup container,

                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_home, container, false);

        Envelope env = new Envelope(105.50485954224524, 21.04870508156068, 105.75256390997109, 21.09248760188878);

        mv = (MapView)rootView.findViewById(R.id.map);

        mv.addLayer(new ArcGISTiledMapServiceLayer(

                this.getResources().getString(R.string.basemap_url)));

        mv.setMapBackground(Color.WHITE, Color.MAGENTA, 0, 0);

        mv.addLayer( new ArcGISFeatureLayer(

                "http://172.20.10.6/hanoi/rest/services/Hanoi/Cay/FeatureServer/0",

                ArcGISFeatureLayer.MODE.SNAPSHOT));

        return mv;

    }

}

 

And here is my layout

 

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent">

 

 

    <com.esri.android.map.MapView

        android:id="@+id/map"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

 

 

        mapoptions.center="34.056215, -117.195668"

        mapoptions.ZoomLevel="16">

 

 

        <com.esri.android.map.ags.ArcGISFeatureLayer

            Url="http://172.20.10.6/hanoi/rest/services/Hanoi/Cay/FeatureServer/0"

            mode="SNAPSHOT" />

    </com.esri.android.map.MapView>

 

Help me to solve this problem please. thanks!

Outcomes