0

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();
Stedy
  • 7,359
  • 14
  • 57
  • 77
user1094717
  • 31
  • 1
  • 4
  • You can only have 1 mapview per activity. Anything you do here will definitely be a hack. – Falmarri Dec 13 '11 at 00:40
  • @Falmarri - I am trying to build a magnify tool. How can I achieve it without having 2 mapview objects in the same activity? Is there a way where I can show one of them as an image? – user1094717 Dec 13 '11 at 14:55

1 Answers1

0

We cannot have more than one MapView objects in a single ArcGIS based Android application. Hence, we cannot use ViewSwitcher to accomplish this task.

user1094717
  • 31
  • 1
  • 4