2011-01-10 2 views
4

지금은 단일 활동과 별도의보기로 내 응용 프로그램 탭 호스트에서 사용하고 있습니다.TabHost 내부에서보기 변경 (하나의 활동, 여러보기)

탭 활동 :

super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    TabHost tabs = (TabHost) findViewById(R.id.tabhost);   
    tabs.setup(); 

    TabHost.TabSpec spec = tabs.newTabSpec(TAB_HOTELS); 
    spec.setContent(R.id.tab1); 
    spec.setIndicator("Hotels"); 
    tabs.addTab(spec); 

    spec = tabs.newTabSpec(TAB_LAST_MINUTE); 
    spec.setContent(R.id.tab2); 
    spec.setIndicator("Last Minute"); 
    tabs.addTab(spec); 

레이아웃

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tabhost" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout android:orientation="vertical" 
     android:layout_width="fill_parent" android:layout_height="fill_parent"> 
     <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:layout_width="fill_parent" 
       android:layout_height="fill_parent" android:id="@+id/tab1" 
       android:orientation="vertical"> 
       <ListView android:id="@+id/listaLocalita" 
        android:layout_width="fill_parent" android:layout_height="wrap_content" /> 
      </LinearLayout> 

      <LinearLayout android:layout_width="fill_parent" 
       android:layout_height="fill_parent" android:id="@+id/tab2" 
       android:orientation="vertical" android:paddingTop="60px"> 
       <TextView android:layout_width="fill_parent" 
        android:layout_height="100px" android:text="This is tab 2" 
        android:id="@+id/txt2" /> 
      </LinearLayout> 
     </FrameLayout> 
    </LinearLayout> 
</TabHost> 

그리고 내가 한 단계 깊이를 사용하고 같은 일이 아주 잘 한 노력하고 있습니다. 불행히도 다음과 같이 작동하도록 탭 중 하나를 만들어야합니다.

탭로드 ListView는 도시 목록, 도시 이름에 대한 사용자 클릭, 탭의 내용은 호텔 목록으로 대체되며 사용자는 호텔을 선택하고 항상 같은 탭에서 호텔의 정보가로드됩니다.

이 시나리오를 어떻게 달성 할 수 있습니까? LayoutInflater?

미리 감사드립니다.

+0

혹시 이것을 알아 냈습니까? 나는 비슷한 것을하고있다. –

+0

[이 예] (http://ericharlow.blogspot.in/2010/09/experience-multiple-android-activities.html)를 참조하십시오. 희망이 당신을 도울 것입니다. –

답변

0

의도를 사용하여 활동을 탭 컨텐츠로 설정할 수 있으며이 활동은 listView 또는 다른 활동 중 하나를 호출 할 수 있습니다.

/** tid1 is firstTabSpec Id. Its used to access outside. */ 
     TabSpec MainTab = tabHost.newTabSpec("tag1"); 
     TabSpec SearchTab = tabHost.newTabSpec("tag2"); 
     TabSpec MessageTab = tabHost.newTabSpec("tag3"); 
     TabSpec ServicesTab = tabHost.newTabSpec("tag4"); 
     TabSpec SettingsTab = tabHost.newTabSpec("tag5"); 

     MainTab.setIndicator("Main", res.getDrawable(R.drawable.anchor_36)); 
     MainTab.setContent(new Intent(this, MainView.class)); 

    SearchTab.setIndicator("Search", res.getDrawable(R.drawable.clock_36)); 
    SearchTab.setContent(new Intent(this, SearchView.class)); 

    MessageTab.setIndicator("Messages", res 
      .getDrawable(R.drawable.dialog_36)); 
    MessageTab.setContent(new Intent(this, MessagesView.class)); 

    ServicesTab.setIndicator("Services", res 
      .getDrawable(R.drawable.cloud_36)); 
    ServicesTab.setContent(new Intent(this, ServicesView.class)); 

    SettingsTab.setIndicator("Settings", res 
      .getDrawable(R.drawable.settings_36)); 
    SettingsTab.setContent(new Intent(this, SettingsView.class)); 

    /** Add tabSpec to the TabHost to display. */ 
    tabHost.addTab(MainTab); 
    tabHost.addTab(SearchTab); 
    tabHost.addTab(MessageTab); 
    tabHost.addTab(ServicesTab); 
    tabHost.addTab(SettingsTab); 

지금로드 활동에 당신은 당신을 위해 작동합니다

StartActivity(new intent(currentActivity.this, newActivity.class)); 

이 같은 코드를 사용할 수 있습니다.

+0

shure,하지만 이것은 'newActivity'를 탭 안쪽이 아니라 하나의 윈도우에서 시작합니다 ... –