【发布时间】:2011-10-19 08:25:33
【问题描述】:
我正在使用带有 hack 的 android 兼容性类,以便在此处找到的片段中使用地图视图:https://github.com/petedoyle/android-support-v4-googlemaps
不幸的是,我发现如果 mapfragment 从 Activity 中删除,然后重新读取,我会收到“您只允许在 MapActivity 中有一个 MapView”错误。”
我理解错误背后的原理,并尝试在片段的onPause方法中破坏地图视图。不幸的是,我似乎无法完全破坏地图视图,因为我仍然得到它。我的代码如下所示:
private RelativeLayout layout;
private MapView mp;
public void onResume(){
super.onResume();
Bundle args = getArguments();
if(mp == null)
{
mp = new MapView(getActivity(), this.getString(R.string.map_api_key));
mp.setClickable(true);
}
String request = args.getString("requestId");
layout = (RelativeLayout) getView().findViewById(R.id.mapholder);
layout.addView(mp);
//TextView txt = (TextView) getView().findViewById(R.id.arguments);
//txt.setText(request);
}
public void onPause(){
super.onPause();
layout.removeView(mp);
mp = null;
}
有人对我在这里忽略破坏的参考有什么想法吗?
【问题讨论】:
标签: android view android-mapview android-fragments