我想在单个视图内创建多个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