You are only allowed to have a single MapView in a MapActivity

▼魔方 西西 提交于 2019-11-28 01:43:59

I think everyone was a little right, it seams like a flaw in the API to me. I should be able to inflate a view and use the map in it, if I recall the view then be able to delete it or review it again without error.

The easiest workaround was to remove the inflation or setContentView using the xml and going with a dynamic build of the map, then storing that in memory.

I removed:

// Show Map Settings Screen
setContentView(R.layout.set_map_center);

// Initiate the center point map
if (mapView == null) {
    mapView = (MapView) findViewById(R.id.mapview);
}

And replaced it with:

if (mapView == null) {
   // public MapView mapView = null; // Public defined Variable
   mapView = new MapView(this, this.getString(R.string.APIMapKey));
}

setContentView(mapView);

This works great and gives me chances to call the map. Thanks for responding everyone.

Because you call setContentView(R.layout.set_map_center); more than once. Why do you need to set the contentView here again? Why not put it in onCreate?

cesards

Here there is another solution that worked for me:

FragmentMap + ActionBar Tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!