我想在單個視圖內創建多個tabhosts。在這個例子中,我使用了來自iosched應用程序的代碼示例以及允許用戶左右滑動以在視圖之間滑動的「工作空間」視圖。在一個視圖中創建多個tabhost元素
每個滑動視圖都將包含一個tabhost。
我遇到的問題是,當我填充第二,第三等tabhost的所有內容出現在第一個tabhost,而不是正確的。
我有對象的列表,列表中的每個對象都有一個單獨的tabhost:
Outer loop over each xxx to build a tabhost for each xxx
// Setup views
ctlr.mRootView = (ViewGroup) inflater.inflate(R.layout.controllers_list_content_tabbed, null);
ctlr.scrollView = (ObservableScrollView) ctlr.mRootView.findViewById(R.id.controllers_scroll);
ctlr.scrollView.setOnScrollListener(this);
ctlr.mTabHost = (TabHost) ctlr.mRootView.findViewById(android.R.id.tabhost);
ctlr.mTabWidget = (TabWidget) ctlr.mRootView.findViewById(android.R.id.tabs);
ctlr.mTabHost.setup();
ctlr.mTabRealContentView = ctlr.mRootView.findViewById(R.id.realtabcontent);
int mTabReakContentViewId = ctlr.mTabRealContentView.getId();
ctlr.mTabManager = new TabManager(this, ctlr.mTabHost, mTabReakContentViewId);
.
.
. I loop several tabs like the snippet below and I expect each of these tabs on each tabhost
.
// Supply controller uri as an argument.
Bundle args = new Bundle();
args.putInt("controllerId", ctlr.mControllerId);
String tagSpec = TAG_PROBES + "_" + ctlr.mControllerId.toString();
ctlr.mTabManager.addTab(ctlr.mTabHost.newTabSpec(tagSpec)
.setIndicator(buildIndicator(ctlr, R.string.db_maint_probes)),
DbMaintProbesFragment.class,
args);
.
.
.
mWorkspace.addView(ctlr.mRootView);
mCtlrs.add(ctlr); <<-- this is the linked list of all the items added to the workspace
我認爲這個問題是某種相關的事實,每個TabManager在去年new'ed時間它始終使用相同的RealTabContent引用。
任何想法??這真讓我抓狂。
雖然每個tabhost都建立在它們各自的片段中,但我可以看到它們都指的是第一個RealTabContent id。
謝謝您可以提供任何幫助!
對不起,TabManager是一個輔助類,記錄在谷歌示例代碼http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabs.html它有助於管理碎片在選項卡上。 – HeneryH 2012-02-01 22:41:06
上面的代碼片段在我想創建的每個tabhost的循環中執行一次。 – HeneryH 2012-02-01 22:42:44