2012-07-07 1 views
0

예를 들어, 처음에 탭을 설정하는 방법에 대해서는 다음 tutorial을 참조하십시오.하나의 응용 프로그램에서 여러 탭 활동

정상적인 활동이 탭 중 하나에서 실행되는 대신 다른 TabActivity를 원합니다. 그래서 내가하려는 것은 TabActivity 내에서 TabActivity를 실행하는 것입니다. 나는 그 문제가 신분증의 갈등이라고 생각한다. 나는 이차적 인 활동의 xml 파일에있는 ID를 변경하고 수동으로 그 활동을 호출함으로써이 문제를 해결하려고 노력했지만 운이 없었다.

저는이 문제에 대한 해결책을 몇 시간 씩 찾아 보았지만 아무 것도 생각 나지 않았습니다.

답변

0

응용 프로그램에서 여러 탭 활동이 가능합니다.

예를 들어

는 : 탭 1과 탭 2

Tab 1 can be a TabActivity with two or more tabs. 
Tab 2 can be a TabActivity with two or more tabs. 

FirstTab, SecondTab, ThirdTab and FourthTab are simple activities actings as child for child of HomeTabActivity. 

xml files containing TabHost as parent element 
1. hometab.xml 
2. tab1.xml 
3. tab2.xml 

To differentiate between HomeTabActivity and Its child TabActivities i.e Tab1 and Tab2 
I have put TabWidget at top for HomeTabActivity and at bottom for Tab1 and Tab2. 

HomeTabActivity (최초의 메인 탭 활동) : 앱은 실행 프로그램이 탭 TabActivity (HomeTabActivity)를 포함

public class HomeTabActivity extends TabActivity 
{ 
    private TabHost mTabHost = null; 
    private Intent mIntent = null; 
    private TabHost.TabSpec mTabSpec = null; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.hometab); 
     initializeTabs(); 
    } 

    private void initializeTabs() { 
     mTabHost = getTabHost(); 

     mIntent = new Intent().setClass(this, Tab1.class); 
     mTabSpec = mTabHost 
       .newTabSpec("Tab1") 
       .setIndicator("Tab1", 
         getResources().getDrawable(R.drawable.ic_launcher)) 
       .setContent(mIntent); 
     mTabHost.addTab(mTabSpec); 

     mIntent = new Intent().setClass(this, Tab2.class); 
     mTabSpec = mTabHost 
       .newTabSpec("Tab2") 
       .setIndicator("Tab2", 
         getResources().getDrawable(R.drawable.ic_launcher)) 
       .setContent(mIntent); 
     mTabHost.addTab(mTabSpec); 

     mTabHost.setCurrentTab(0); 
    } 

} 

Tab1 (TabActivity는 HomeTabActivity 내부에 포함됨) :

public class Tab1 extends TabActivity 
{ 
    private TabHost mTabHost = null; 
    private Intent mIntent = null; 
    private TabHost.TabSpec mTabSpec = null; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.tab1); 
     initializeTabs(); 
    } 

    private void initializeTabs() { 
     mTabHost = getTabHost(); 
     mIntent = new Intent().setClass(this, FirstTab.class); 

     mTabSpec = mTabHost 
       .newTabSpec("Tab1 Child 1") 
       .setIndicator("Tab1 Child 1", 
         getResources().getDrawable(R.drawable.ic_launcher)) 
       .setContent(mIntent); 
     mTabHost.addTab(mTabSpec); 

     mIntent = new Intent().setClass(this, SecondTab.class); 
     mTabSpec = mTabHost 
       .newTabSpec("Tab1 Child 2") 
       .setIndicator("Tab1 Child 2", 
         getResources().getDrawable(R.drawable.ic_launcher)) 
       .setContent(mIntent); 
     mTabHost.addTab(mTabSpec); 
     mTabHost.setCurrentTab(0); 
    } 
} 

TAB2 (또 다른 HomeTabActivity 안에 내장 TabActivity)

public class Tab2 extends TabActivity 
{ 
    private TabHost mTabHost = null; 
    private Intent mIntent = null; 
    private TabHost.TabSpec mTabSpec = null; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.tab2); 
     initializeTabs(); 
    } 

    private void initializeTabs() { 
     mTabHost = getTabHost(); 
     mIntent = new Intent().setClass(this, ThirdTab.class); 

     mTabSpec = mTabHost 
       .newTabSpec("Tab2 Child 1") 
       .setIndicator("Tab2 Child 1", 
         getResources().getDrawable(R.drawable.ic_launcher)) 
       .setContent(mIntent); 
     mTabHost.addTab(mTabSpec); 

     mIntent = new Intent().setClass(this, FourthTab.class); 
     mTabSpec = mTabHost 
       .newTabSpec("Tab2 Child 2") 
       .setIndicator("Tab2 Child 2", 
         getResources().getDrawable(R.drawable.ic_launcher)) 
       .setContent(mIntent); 
     mTabHost.addTab(mTabSpec); 
     mTabHost.setCurrentTab(1); 
    } 
} 

hometab.xml

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 
     </TabWidget> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 
     </FrameLayout> 
    </LinearLayout> 

</TabHost> 

tab1.xml 및 tab2.xml

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@color/androidblue" 
      android:layout_weight="1"> 
     </FrameLayout> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0"> 
     </TabWidget> 
    </LinearLayout> 

</TabHost> 
관련 문제