I am trying to use ViewSwitcher
to switch between two MapView
objects (GIS based). But I get the following exception at magnifyMap (**line xyz**) mapview
:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
even after removing the child views (MapViews
) from the parent layout (homeScreenLayout
). Following are the relevant snippets.
1) My 1st MapView
is in XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/homeScreenLayout">
<MapView
xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</MapView>
</RelativeLayout>
2) My 2nd MapView
is in my Activity:
MapView map = (MapView) findViewById(R.id.map);
MapView magnifyMap = new MapView(ActivityMap.this);
magnifyMap = _map;
magnifyMap.setExtent(new Envelope(_tappedPoint, 3.0, 3.0));
3) I am using ViewSwitcher
to add these 2 views:
homeScreenLayout.removeView(map);
homeScreenLayout.removeView(magnifyMap);
ViewSwitcher viewSwitcher = new ViewSwitcher(ActivityMap.this);
homeScreenLayout.addView(viewSwitcher);
viewSwitcher.addView(map, 0, new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
// **line xyz**
viewSwitcher.addView(magnifyMap, 1, new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); // line xyz
viewSwitcher.showNext();