删除视图并重新创建它 [英] Delete a view and recreate it

查看:145
本文介绍了删除视图并重新创建它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来删除设置以便

 的setContentView(R.layout.set_map_center);
图形页面=(图形页面)findViewById(R.id.mapview);

如果我再次拨打这个观点后来我得到一个错误说:


  

java.lang.IllegalStateException:您
  只允许有一个单一的
  图形页面在MapActivity



解决方案

我想每个人都有点吧,它接缝像API给我一个缺陷。我应该能够膨胀的视图,使用地图的话,如果我还记得的观点,​​然后才能删除或再次审核无误。

最简单的解决方法是删除使用XML和地图的动态构建下去,然后存储在内存中的通货膨胀或的setContentView。

我删除:

  //查看地图设置屏幕
的setContentView(R.layout.set_map_center);//初始化中心点地图
如果(MapView类== NULL){
    图形页面=(图形页面)findViewById(R.id.mapview);
}

,取而代之的是:

 如果(图形页面== NULL){
   //公共MapView类MapView类= NULL; //公共定义的变量
   图形页面=新的图形页面(这一点,this.getString(R.string.APIMapKey));
}的setContentView(图形页面);

这个伟大的工程,给我的机会来调用地图。感谢您回应大家。

Is there a way to remove a view that was set with

setContentView(R.layout.set_map_center);
mapView = (MapView) findViewById(R.id.mapview);

If I call this view again then I get an error saying:

java.lang.IllegalStateException: You are only allowed to have a single MapView in a MapActivity

解决方案

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.

这篇关于删除视图并重新创建它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆