android - MapFragment ArcGis - The specified child already has a parent -
i'm trying display mapview arcgis in android studio. i'm using map fragments that, put in xml map , other ui stuff. putting mapview
element in layout file crashes, i'm doing way:
my_main_activity.xml
<android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/maps_app_activity_drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" > <!-- main content view --> <framelayout android:id="@+id/maps_app_activity_content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /> <!-- navigation drawer --> <listview android:id="@+id/maps_app_activity_left_drawer" style="@style/drawer_listview_style" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:background="@android:color/darker_gray" android:choicemode="singlechoice" android:divider="@color/esri_gray" android:dividerheight="1px" />
and framgent layout: map_fragment_layout.xml
<framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map_fragment_map_container_frame_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- map configuration --> <com.esri.android.map.mapview android:id="@+id/map_layout" android:layout_width="fill_parent" android:layout_height="fill_parent" initextent = "-9934033.827 1537316.31 -9933312.043 1537940.728" > <!-- xmin ymin xmax ymax --> </com.esri.android.map.mapview>
my map fragment class holds every configuration of mapview
:
@override public view oncreateview(layoutinflater inflater, viewgroup container,bundle savedinstancestate) { mmapcontainer = (framelayout) inflater.inflate(r.layout.map_fragment_layout,container,false); // add dynamic layer mapview (base) // retrieve map , initial extent xml layout mapview mapview = (mapview)mmapcontainer.findviewbyid(r.id.map_layout); arcgisdynamicmapservicelayer basemap = new arcgisdynamicmapservicelayer(basemapurl); mapview.addlayer(basemap); //creates dynamic layer using service url arcgisdynamicmapservicelayer dynamiclayer = new arcgisdynamicmapservicelayer(dynamicmapurl); //adds layer 'mapview' mapview.addlayer(dynamiclayer); // set mapview allow user rotate map when part of pinch gesture. setmapview(mapview); mapview.zoomin(); return mmapcontainer; }
the function setmapview
configures rest of mapview options:
private void setmapview(final mapview mapview) { mmapview = mapview; mmapview.setesrilogovisible(false); mmapview.enablewraparound(true); mapview.setallowrotationbypinch(true); // creating inflater minflater = (layoutinflater) getactivity().getsystemservice(context.layout_inflater_service); // setting layout params searchview , searchresult layout mlayoutparams = new framelayout.layoutparams(layoutparams.match_parent,layoutparams.wrap_content, gravity.left | gravity.top); mlayoutparams.setmargins(left_margin_search, top_margin_search,right_margin_search, bottom_margin_search); // set mapview activity layout mmapcontainer.addview(mmapview); // displaying searchbox layout showsearchboxlayout();
after debuging error shows up:
java.lang.runtimeexception: unable start activity componentinfo{zero.ucamaps/zero.ucamaps.mainactivity}: java.lang.illegalstateexception: specified child has parent. must call removeview() on child's parent first. @ android.app.activitythread.performlaunchactivity(activitythread.java:2325) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2387) @ android.app.activitythread.access$800(activitythread.java:151) @ android.app.activitythread$h.handlemessage(activitythread.java:1303) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5254) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:903) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:698) caused by: java.lang.illegalstateexception: specified child has parent. must call removeview() on child's parent first. @ android.view.viewgroup.addviewinner(viewgroup.java:3936) @ android.view.viewgroup.addview(viewgroup.java:3786) @ android.view.viewgroup.addview(viewgroup.java:3727) @ android.view.viewgroup.addview(viewgroup.java:3700) @ zero.ucamaps.mapfragment.setmapview(mapfragment.java:313) @ zero.ucamaps.mapfragment.oncreateview(mapfragment.java:209) @ android.app.fragment.performcreateview(fragment.java:2053)
i've tried removing the mapview it's parent before returning getmapview(), , still crashes. @ appreciated.
you're trying add mapview
same container twice, once in java , once in xml.
in map_fragment_layout.xml
, create mapview
child of framelayout
called map_fragment_map_container_frame_layout
. that's fine.
then in setmapview
, call mmapcontainer.addview(mmapview)
, tries add mapview
again child of same framelayout
. causes exception , unnecessary. remove line of code.
Comments
Post a Comment