2012-02-01 38 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

相關問題