2011-10-31 63 views
0
protected void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splash); 

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

    TabSpec homeTabSpec = tabHost.newTabSpec("tid1"); 
    TabSpec videoTabSpec = tabHost.newTabSpec("tid1"); 
    TabSpec aboutUsTabSpec = tabHost.newTabSpec("tid1"); 

    homeTabSpec.setIndicator("Home").setContent(new Intent(this,FirstActivity.class)); 
    homeTabSpec.setIndicator("tid1",getResources().getDrawable(R.drawable.home)); 

    videoTabSpec.setIndicator("Video").setContent(new Intent(this,VideoWeb.class)); 
    videoTabSpec.setIndicator("tid1",getResources().getDrawable(R.drawable.videos)); 

    aboutUsTabSpec.setIndicator("About Us").setContent(new  Intent(this,AboutWeb.class)); 
    aboutUsTabSpec.setIndicator("tid1",getResources().getDrawable(R.drawable.aboutus)); 

    tabHost.addTab(homeTabSpec); 
    tabHost.addTab(videoTabSpec); 
    tabHost.addTab(aboutUsTabSpec); 
} 

我xml--TabHost不顯示任何

<?xml version="1.0" encoding="utf-8"?> 

<TabHost android:layout_width="fill_parent" 

android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android" 

android:id="@android:id/tabhost"> 

<LinearLayout android:id="@+id/LinearLayout01" 

android:orientation="vertical" android:layout_height="fill_parent" 

android:layout_width="fill_parent"> 

<TabWidget android:id="@android:id/tabs" 

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

<FrameLayout android:id="@android:id/tabcontent" 

android:layout_height="fill_parent" android:layout_width="fill_parent"></FrameLayout> 

</LinearLayout> 

</TabHost> 
+1

看來,錯誤是推出你的'FirstClass'內 - 你可以張貼的代碼? – kaspermoerch

+0

at com.example.vidushi.Home.onCreate(Home.java:44)表示它在第44行,你有沒有調試過這個步驟來查看所有變量的狀態?有些東西是空的。 – Jack

+0

感謝您的答覆,它工作。我想從底部顯示tabhost。你告訴我如何?我顯示我的XML。 – arpit

回答

2

如果你沒有在你的XML佈局定義的TabActivity,你應該叫tabHost.setup()添加任何東西給它。

所以它應該是:

TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); 
tabHost.setup() 
+0

您好我想從底部顯示我的tabhost我該如何做到這一點? – arpit

+0

閱讀此答案:http://stackoverflow.com/questions/2395661/android-tabs-at-the-bottom/2710404#2710404 –