2012-03-23 46 views
-2

我的应用程序中显示tabhost时出现问题。我试过任何类型的代码。我知道我必须调用tabwidget @android:id/tabs和其他类似的东西,但我仍然无法设法在我的应用程序中显示选项卡式视图。我需要4个标签,我不知道该怎么做。你可以帮帮我吗?????TabHost不显示

正如一些你想要的代码,那就是:

<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 

     <TextView 
      android:id="@+id/textview1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="this is a tab" /> 

     <TextView 
      android:id="@+id/textview2" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="this is another tab" /> 

     <TextView 
      android:id="@+id/textview3" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="this is a third tab" /> 
    </FrameLayout> 
</LinearLayout> 

并在Java:

TabHost mTabHost = (TabHost)findViewById(android.R.id.tabhost); 

    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.id.textview1)); 
    mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.textview2)); 
    mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(R.id.textview3)); 

    mTabHost.setCurrentTab(0); 

这是我从链接承担了代码第一个答案。

+0

即使我们不知道该回答什么。请提供一些代码或提及您遇到的错误。 – xyz 2012-03-23 16:35:39

+0

我没有任何代码,我只是用我在互联网上发现的东西尝试过 – Cippo 2012-03-23 16:38:00

+1

到目前为止你得到了什么?你能显示一些代码吗? – goodm 2012-03-23 16:38:41

回答

1

欢迎来到SO。在提出任何问题之前,请确保您尝试了一些问题并针对您遇到的任何问题提出问题。
试试这个Hello World example
我认为这包含了所有必需的信息。

+0

我在询问之前颠倒了谷歌,我尝试了一切,但它总是一样的。它根本不起作用。即使是你发布的这个。 – Cippo 2012-03-23 16:47:23

+2

我做到了!!!!!我应该写mTabHost.setup();申报后!!!! – Cippo 2012-03-23 17:01:17

0

在添加选项卡之前调用mTabHost.setup()。

相关问题