2012-03-23 4 views
-2

アプリケーションにタブホストを表示しているときに問題があります。私はどんなタイプのコードを試してみました。私は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

+0

私はコードを持っていない、私はちょうど私がインターネットで見つけたものを試した – Cippo

+1

あなたはこれまでに何を持っていますか?いくつかのコードを表示できますか? – goodm

答えて

1

ようこそ。質問をする前に何か試してみて、問題が何であっても質問をしてください。
お試しくださいHello World example
これにはすべての必須情報が含まれていると思います。

+0

私は質問する前にgoogleを逆にしました。私はすべてを試しましたが、常に同じです。単に機能しません。これもあなたが投稿したものです。 – Cippo

+2

私はそれをやった!!!!!私はmTabHost.setup()を書く必要があります。宣言後!!!! – Cippo

0

タブを追加する前にmTabHost.setup()を呼び出します。