
我有一个显示地图页面的功能,所以我可以让用户选择他们当前的位置.但是如果你运行这个函数两次,它会在MapActivity错误中使用Single MapVIEw崩溃应用程序(即再次打开该设置视图).
public voID showMapSetterPage(VIEw v) { Log.i(DEBUG_TAG, "Settings screen, set map center launched"); // Set which vIEw object we fired off from set_pv(v); // Show Map Settings Screen setContentVIEw(R.layout.set_map_center); // Initiate the center point map if (mapVIEw == null) { mapVIEw = (MapVIEw) findVIEwByID(R.ID.mapvIEw); } mapVIEw.setLongClickable(true); mapVIEw.setStreetVIEw(true); mapVIEw.setBuiltInZoomControls(false); mapVIEw.setSatellite(false); mapController = mapVIEw.getController(); mapController.setZoom(18); LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location location = lm .getLastKNownLocation(LocationManager.GPS_PROVIDER); int lat = (int) (location.getLatitude() * 1E6); int lng = (int) (location.getLongitude() * 1E6); Log.i(DEBUG_TAG, "The LAT and LONG is: " + lat + " == " + lng); point = new GeoPoint(lat, lng); // mapController.setCenter(point); mapController.animateto(point);}所以我有一个显示此VIEw和onClick =“showMapSetterPage”的按钮.但是,如果您从地图中返回设置屏幕并再次单击该按钮,则会收到以下错误:
03-06 20:55:54.091:
ERROR/AndroIDRuntime(28014): Caused
by: java.lang.IllegalStateException:
You are only allowed to have a single
MapVIEw in a MapActivity
如何删除MapVIEw并重新创建它?
解决方法:
我认为每个人都是对的,它对我来说就像是一个缺陷.我应该能够给视图充气并在其中使用地图,如果我回想起视图,那么就可以删除它或者再次查看它而不会出错.
最简单的解决方法是使用xml删除膨胀或setContentVIEw,并使用动态构建的映射,然后将其存储在内存中.
我删除了:
// Show Map Settings ScreensetContentVIEw(R.layout.set_map_center);// Initiate the center point mapif (mapVIEw == null) { mapVIEw = (MapVIEw) findVIEwByID(R.ID.mapvIEw);}并替换为:
if (mapVIEw == null) { // public MapVIEw mapVIEw = null; // Public defined Variable mapVIEw = new MapVIEw(this, this.getString(R.string.APIMapKey));}setContentVIEw(mapVIEw);这很好用,让我有机会打电话给地图.感谢您回复所有人.
总结以上是内存溢出为你收集整理的android – 您只能在MapActivity中拥有一个MapView全部内容,希望文章能够帮你解决android – 您只能在MapActivity中拥有一个MapView所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)