2009-06-30 10 views
3

私は現在Android 1.5 SDKを試しています。私はTabHostに関するいくつかの例を見てきました。 私がしようとしているのは、各タブで別のボタンを使ってタスクを実行することです。タブホストとボタンを使ったAndroid 1.5のプログラミング

私が試したこと はonClickListiner()とonClick()を使用していました。私はこれがすべての開発者が使用しているものだと思いますが、ボタンを押すたびにLogCatでnull例外が発生し続けます。適切にボタン/ TextViewの作業を行うための最善の方法は何でしょう

firstTabLayout = layout for Button and TextView. 

(のsetContent(R.id.firstTabLayout)...)tab.add:また、私はので、私のようにタブを呼び出し、各XMLレイアウトを持っていますTabHostの下で?

答えて

0

私はあなたの問題がどこにあるか全くわからないんだけど、これは私が

layout.xml

<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"> 

    <LinearLayout android:id="@+id/tab1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <TextView android:id="@android:id/text" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 
    <LinearLayout android:id="@+id/tab2" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <TextView android:id="@android:id/text" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 
    <LinearLayout android:id="@+id/tab3" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <TextView android:id="@android:id/text" 
      android:layout_width="fill_parent" 
       android:layout_height="wrap_content" /> 

    </LinearLayout> 
</FrameLayout> 

前に私のタブ付きの活動を設定した方法です

Tab.java

public class InitialActivity extends TabActivity { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.layout); 

     TabHost th = getTabHost(); 
     th.addTab(th.newTabSpec("tab_1").setIndicator("Tab1").setContent(R.id.tab1)); 
     th.addTab(th.newTabSpec("tab_2").setIndicator("Tab2").setContent(R.id.tab2)); 
     th.addTab(th.newTabSpec("tab_3").setIndicator("Tab3").setContent(R.id.tab3)); 
    } 
} 

次に、あなただけのタブ内の任意のビューにfindViewById()を使用することができ、またはそれらの間の共有名がある場合は、あなたがfindViewById(R.id.tab1).findViewById(R.id.text)

を行うことができます
関連する問題