2012-02-01 89 views
0

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

谢谢您可以提供任何帮助!

回答

0

什么是TabManager?我无法在Android开发文档中找到它。

从我所看到的,你只是创建一个TabHost和一个TabManager,并添加标签。当然你想要不止一个?

我会使用ViewFlipper并添加许多线性布局。然后,我会将选项卡主机添加到每个线性布局。这将创建多个“屏幕”,当您向左/向右滑动时,您可以将它们连接起来,每个“屏幕”都有自己的一组标签。

+0

对不起,TabManager是一个辅助类,记录在谷歌示例代码http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabs.html它有助于管理碎片在选项卡上。 – HeneryH 2012-02-01 22:41:06

+0

上面的代码片段在我想创建的每个tabhost的循环中执行一次。 – HeneryH 2012-02-01 22:42:44

相关问题