每次我调用这个函数时,我都会膨胀一个地图视图。并且每次都删除视图。但我仍然收到一个错误,说孩子已经有了父母,请先调用 removeview()。
关于如何解决这个问题的任何想法。
void getGeoView(Context context) {
myRoot.removeAllViews();
LayoutInflater inflater = (LayoutInflater) this
.getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.geo_inflator, null);
((ViewGroup) view.findViewById(R.id.myMap)).removeAllViews();
if (mapView == null) {
mapView = new MapView(this, "0IEmqsWhwmo6Cu8hKdYn_VudUT8IpdKpXzMvQyw");
((ViewGroup) view.findViewById(R.id.myMap)).addView(mapView);
} else {
((ViewGroup) view.findViewById(R.id.myMap)).addView(mapView);
}