问题
I have a fragmentActivity where I build a tabHost and in each tab there is a Fragment. Well, I haver four tabs 3 with info and 1 with a fragment where is included a google-map-v2 (is a fragmentMAp in a Fragment because I want to add buttons etc.), when I select one tab and pass to other everything go well, but when I select the map tab, after that other tab and again the map tab an error is throw.
My view seems like:
|__||__|__|__|
| __________ |
|| FRAGMENT ||
||_____ _ ||
|| FRAG| |_|||
|| MAP | ||
|| | ||
||_____| ||
||__________||
The error:
01-29 08:32:56.979: E/AndroidRuntime(27738): FATAL EXCEPTION: main
01-29 08:32:56.979: E/AndroidRuntime(27738): android.view.InflateException: Binary XML file line #11: Error inflating class fragment
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-29 08:32:56.979: E/AndroidRuntime(27738): at com.monumentos.vistasmovil.MonumentoMapa.onCreateView(MonumentoMapa.java:127)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1264)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:672)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
01-29 08:32:56.979: E/AndroidRuntime(27738): at com.monumentos.vistasmovil.Monumento.onTabChanged(Monumento.java:279)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.widget.TabHost.invokeOnTabChangeListener(TabHost.java:436)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.widget.TabHost.setCurrentTab(TabHost.java:421)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:158)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:459)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.view.View.performClick(View.java:2552)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.view.View$PerformClick.run(View.java:9229)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.os.Handler.handleCallback(Handler.java:587)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.os.Handler.dispatchMessage(Handler.java:92)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.os.Looper.loop(Looper.java:138)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.app.ActivityThread.main(ActivityThread.java:3701)
01-29 08:32:56.979: E/AndroidRuntime(27738): at java.lang.reflect.Method.invokeNative(Native Method)
01-29 08:32:56.979: E/AndroidRuntime(27738): at java.lang.reflect.Method.invoke(Method.java:507)
01-29 08:32:56.979: E/AndroidRuntime(27738): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
01-29 08:32:56.979: E/AndroidRuntime(27738): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
01-29 08:32:56.979: E/AndroidRuntime(27738): at dalvik.system.NativeStart.main(Native Method)
01-29 08:32:56.979: E/AndroidRuntime(27738): Caused by: java.lang.IllegalArgumentException: Binary XML file line #11: Duplicate id 0x7f06005c, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
01-29 08:32:56.979: E/AndroidRuntime(27738): ... 27 more
The error say:
01-29 08:32:56.979: E/AndroidRuntime(27738): Caused by: java.lang.IllegalArgumentException: Binary XML file line #11: Duplicate id 0x7f06005c, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285)
01-29 08:32:56.979: E/AndroidRuntime(27738): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
01-29 08:32:56.979: E/AndroidRuntime(27738): ... 27 more
Here is the problem, but I dont know why only this fragment have the problem:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.monumenos_view_preview, container, false);
return view;
}
回答1:
Finally I found the solution, I removed the nested MapFragment in my Fragment:
public void onDestroyView ()
{
try{
SupportMapFragment fragment = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.mapv2));
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.remove(fragment);
ft.commit();
}catch(Exception e){
}
super.onDestroyView();
}
I get the solution from here: Fragments within Fragments
来源:https://stackoverflow.com/questions/14578048/error-with-google-maps-v2-in-tab-mapfragment-in-fragment