作爲標題狀態,我試圖讓它包含在片段中的tabhost,其中標籤內容由片段定義。好吧然後,android:tabhost在片段中,w /片段作爲標籤
我從FragmentsTab例子從谷歌開始。這顯示瞭如何使用片段作爲標籤內容,但TabHost
本身仍被託管在一個活動中。再次,我需要選項卡託管在一個片段。
我拿了FragmentsTab
例如,並且在onCreate()
移動代碼,並在我的Fragment
它搬到onCreateView()
,
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View fragmentView = inflater.inflate(R.layout.detail_fragment, container);
mTabHost = (TabHost) fragmentView.findViewById(android.R.id.tabhost);
mTabHost.setup();
mTabManager = new TabManager(getActivity(), mTabHost, R.id.realtabcontent);
// TODO: localize
mTabManager.addTab(mTabHost.newTabSpec("info").setIndicator("File Info"), InfoFragment.class, null);
return fragmentView;
}
當我運行,我得到這個例外,
05-25 14:42:27.272: E/AndroidRuntime(4701): Caused by: java.lang.IllegalStateException: Recursive entry to executePendingTransactions
05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1343)
05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:429)
05-25 14:42:27.272: E/AndroidRuntime(4701): at com.zimbra.octopus.android.TabManager.onTabChanged(TabManager.java:116)
05-25 14:42:27.272: E/AndroidRuntime(4701): at android.widget.TabHost.invokeOnTabChangeListener(TabHost.java:359)
05-25 14:42:27.272: E/AndroidRuntime(4701): at android.widget.TabHost.setCurrentTab(TabHost.java:344)
05-25 14:42:27.272: E/AndroidRuntime(4701): at android.widget.TabHost.addTab(TabHost.java:216)
05-25 14:42:27.272: E/AndroidRuntime(4701): at com.zimbra.octopus.android.TabManager.addTab(TabManager.java:92)
05-25 14:42:27.272: E/AndroidRuntime(4701): at com.zimbra.octopus.android.DetailFragment.onCreateView(DetailFragment.java:46)
05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:819)
05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1053)
05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1371)
05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:429)
05-25 14:42:27.272: E/AndroidRuntime(4701): at com.zimbra.octopus.android.TabManager.onTabChanged(TabManager.java:116)
05-25 14:42:27.272: E/AndroidRuntime(4701): at android.widget.TabHost.invokeOnTabChangeListener(TabHost.java:359)
05-25 14:42:27.272: E/AndroidRuntime(4701): at android.widget.TabHost.setCurrentTab(TabHost.java:344)
05-25 14:42:27.272: E/AndroidRuntime(4701): at android.widget.TabHost.addTab(TabHost.java:216)
05-25 14:42:27.272: E/AndroidRuntime(4701): at com.zimbra.octopus.android.TabManager.addTab(TabManager.java:92)
05-25 14:42:27.272: E/AndroidRuntime(4701): at com.zimbra.octopus.android.DetailFragment.onCreateView(DetailFragment.java:46)
05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:819)
05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1032)
05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1111)
05-25 14:42:27.272: E/AndroidRuntime(4701): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:264)
05-25 14:42:27.272: E/AndroidRuntime(4701): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
看着跟蹤,我看到爲DetailFragment
(片段託管TabHost
)調用遞歸。不知何故,TabManager.addTab()
(再次參見FragmentsTab示例)的調用導致對DetailFragment.onCreateView()
的遞歸調用。
我在做什麼錯?這甚至有可能嗎? 謝謝。
你是不是想給另一個片段中嵌入一個片段,是嗎? –
是的,我是。我想你會告訴我這是我的問題,對嗎? –
是的,框架不允許你這樣做......對此感到遺憾-_- –