2009-06-30 5 views
3

현재 Android 1.5 SDK를 시험해보고 있으며 TabHost에 대한 몇 가지 예를 살펴 보았습니다. 내가하려는 일은 각 탭에서 다른 버튼을 사용하여 작업을 수행하는 것입니다.TabHost 및 버튼으로 Android 1.5 프로그래밍

는 onClickListiner() 및 onClick()을 사용하고있었습니다. 나는 이것이 모든 개발자들이 사용하는 것이라고 생각하지만, 버튼을 누를 때마다 LogCat에 null 예외가 계속 발생합니다. 또한 나는대로 탭을 호출 각각의 XML 레이아웃이 있습니다 tab.add (...의 setContent (R.id.firstTabLayout))를

firstTabLayout = layout for Button and TextView. 
제대로 버튼/텍스트 뷰 작업을 할 수있는 가장 좋은 방법이 될 것입니다 무엇

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)

관련 문제