【发布时间】:2014-09-06 10:28:01
【问题描述】:
我在片段中使用地图。第一次加载良好,但当我调用它时第二次出错 -
: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
xml代码-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/mapfragment"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_gravity="center_horizontal"
class="com.google.android.gms.maps.SupportMapFragment" />
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/mapfragment"
/>
</RelativeLayout>
java代码-
map = ((SupportMapFragment)getActivity().getSupportFragmentManager().findFragmentById(R.id.mapfragment)).getMap();
提到了很多关于堆栈的问题,也尝试了下面的代码但没有工作 -
public void onDestroyView() {
super.onDestroyView();
Fragment fragment = (getFragmentManager().findFragmentById(R.id.mapfragment));
android.support.v4.app.FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.remove(fragment);
ft.commit();
}
使用临时解决方案 -
我通过传递地图片段整数值重新启动片段活动,以便在打开片段活动后直接加载地图片段。
【问题讨论】:
-
第二次做什么?请发布第二次相关代码。
-
发布的代码只是相关的。我在片段中做这一切。第一次我打开地图片段..然后在另一个片段之后当我试图打开地图片段时得到这个错误跨度>
-
你看到这些答案了吗??? Here 和 Here - Preffered Solution
-
@NadeemIqbal 是我已经提到过我在堆栈上提到了许多问题。请再次阅读我的问题。我已经完成了那部分
-
我也遇到了这个错误。我只能在每次替换它时实例化 Fragment 来修复它。我在 SO 中找到的所有解决方案都对我不起作用。
标签: android android-fragments map