3

I have the following code:

setContentView(R.layout.maplayout);
// Create Rotate view
mRotateView = new RotateView(this);

// create a map view
mapView = (MapView) findViewById(R.id.mapview);

mRotateView.addView(mapView); // error here
setContentView(mRotateView);
mylocation = new MyLocationOverlay(this,mapView);

But when I add the view I get an error that says that the specified child already has a parent. I assume this is because the mapView is already a child of the layout.

So, how do I resolve this?

4

1 回答 1

0

Option #1: Put RotateView in your res/layout/maplayout.xml resource as the parent of the MapView widget, so you do not have to set that up in Java code.

Option #2: Remove the MapView from your res/layout/maplayout.xml resource, create an instance of it via its constructor, and add it to your RotateView in Java code.

Option #3: Call removeView() on the parent to remove the MapView from it before calling addView() to add it to the RotateView.

于 2012-04-05T14:06:24.373 回答