在我的应用程序中有一个SherlockFragmentActivity,其中有6个片段。其中一个片段包含map-fragment。
问题:现在问题是当我启动应用程序时地图加载成功,但是当我转到其他片段然后再次尝试加载map-fragment时,它不会加载并给出错误。< / p>
我还试图删除视图,但它也无法正常工作
这是我的代码,
public class SearchMapFragment extends SherlockFragment implements
OnMyLocationButtonClickListener, ConnectionCallbacks,
OnConnectionFailedListener, LocationListener,
OnInfoWindowClickListener, OnMarkerClickListener, OnMapClickListener {
private static View mView;
private GoogleMap mMap;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
if(mView != null){
((ViewGroup)mView.getParent()).removeAllViews();
}
mView = inflater.inflate(R.layout.fragment_search_map, null);
if (mMap == null) {
mf = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.fragment_searchMap);
mMap = mf.getMap();
}
return mView;
}
}
这是我的LogCat,
10-03 15:58:08.473: W/dalvikvm(14911): threadid=1: thread exiting with
uncaught exception (group=0x40adc9f0)
10-03 15:58:08.503: E/AndroidRuntime(14911): FATAL EXCEPTION: main
10-03 15:58:08.503: E/AndroidRuntime(14911): android.view.InflateException: Binary XML file line #49: Error inflating class fragment
10-03 15:58:08.503: E/AndroidRuntime(14911): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
10-03 15:58:08.503: E/AndroidRuntime(14911): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
10-03 15:58:08.503: E/AndroidRuntime(14911): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
10-03 15:58:08.503: E/AndroidRuntime(14911): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
10-03 15:58:08.503: E/AndroidRuntime(14911): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
10-03 15:58:08.503: E/AndroidRuntime(14911): at in.vs2.realestate.fragments.SearchMapFragment.onCreateView(SearchMapFragment.java:103)
10-03 15:58:08.503: E/AndroidRuntime(14911): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
10-03 15:58:08.503: E/AndroidRuntime(14911): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
10-03 15:58:08.503: E/AndroidRuntime(14911): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
10-03 15:58:08.503: E/AndroidRuntime(14911): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
10-03 15:58:08.503: E/AndroidRuntime(14911): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
10-03 15:58:08.503: E/AndroidRuntime(14911): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
10-03 15:58:08.503: E/AndroidRuntime(14911): at android.os.Handler.handleCallback(Handler.java:605)
10-03 15:58:08.503: E/AndroidRuntime(14911): at android.os.Handler.dispatchMessage(Handler.java:92)
10-03 15:58:08.503: E/AndroidRuntime(14911): at android.os.Looper.loop(Looper.java:137)
10-03 15:58:08.503: E/AndroidRuntime(14911): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-03 15:58:08.503: E/AndroidRuntime(14911): at java.lang.reflect.Method.invokeNative(Native Method)
10-03 15:58:08.503: E/AndroidRuntime(14911): at java.lang.reflect.Method.invoke(Method.java:511)
10-03 15:58:08.503: E/AndroidRuntime(14911): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
10-03 15:58:08.503: E/AndroidRuntime(14911): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
10-03 15:58:08.503: E/AndroidRuntime(14911): at dalvik.system.NativeStart.main(Native Method)
10-03 15:58:08.503: E/AndroidRuntime(14911): Caused by: java.lang.IllegalArgumentException: Binary XML file line #49: Duplicate id 0x7f050075, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
10-03 15:58:08.503: E/AndroidRuntime(14911): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
10-03 15:58:08.503: E/AndroidRuntime(14911): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
10-03 15:58:08.503: E/AndroidRuntime(14911): ... 20 more
答案 0 :(得分:1)
您错误地将SupportMapFragment
添加到您的片段中。
请阅读nested fragments。
当嵌套碎片记住这些东西时:
getChildFragmentManager
,SupportMapFragment
。