Android片段Google Maps V2:膨胀类时出错
我正在开发一个使用fragment选项卡的应用程序,我的一个fragment使用Google Maps V2 SupportMapFragment 我的xml:Android片段Google Maps V2:膨胀类时出错,android,android-fragments,Android,Android Fragments,我正在开发一个使用fragment选项卡的应用程序,我的一个fragment使用Google Maps V2 SupportMapFragment 我的xml: <RelativeLayout android:id="@+id/map_container" android:layout_width="fill_parent" android:layout_height="fill_parent"> <fragment android:id="
<RelativeLayout
android:id="@+id/map_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="com.google.android.gms.maps.SupportMapFragment"
/>
</RelativeLayout>
我从这里调用B Fragment A->B,当我从B->返回时,一个片段onCreateView抛出一个异常,android.view.InflateException:Binary XML文件第132行:创建映射片段后,当再次返回到该片段时,错误膨胀类片段,调用片段为onCreateView,这就是为什么要强制关闭
在包含地图的片段中尝试一次
@Override
public void onDestroyView() {
super.onDestroyView();
Fragment f = getFragmentManager().findFragmentById(R.id.map);
if (f != null)
getFragmentManager().beginTransaction().remove(f).commit();
}
请评论我的结果检查我的答案,所以在这个链接上:嘿,纳雷什·雷迪,谢谢你回答我的问题。。。因为我使用的是片段选项卡,所以我使用一个基本容器来处理选项卡中的视图层次结构,您的代码不起作用,但我使用getFragmentManager来处理getFragmentManager,然后它就像一个符咒一样工作。。。
public void onDestroyView() {
super.onDestroyView();
Log.d(TAG, "onDestroyView");
Fragment f = getActivity()
.getSupportFragmentManager().findFragmentById(R.id.map);
if (f != null) {
getActivity().getSupportFragmentManager()
.beginTransaction().remove(f).commit();
}
}
public void onDestroyView() {
super.onDestroyView();
Log.d(TAG, "onDestroyView");
Fragment f = getActivity()
.getSupportFragmentManager().findFragmentById(R.id.map);
if (f != null) {
getActivity().getSupportFragmentManager()
.beginTransaction().remove(f).commit();
}
}