2011-07-13 3 views
0

私のアプリケーションでアンドロイドのタブを使用しています。私はそこに私のタブをインポートするメインクラスを持っています。 4つのタブがあるので、それぞれに1つのJavaクラスがあります。しかし、それぞれのタブでは、私はまた別の意図に行く。あるタブから他のインテントに移動すると、タブビューは消えます。私はタブをすべてのクラスとすべてのビューに残したい。私はそのために何をすべきですか?これは私のメインタブクラスのコードです。Androidタブホストの問題

意図インテント1; Intent intent2; Intent intent3; Intent intent4;このコードはあなたを助けるかもしれ

intent1 = new Intent().setClass(this, x.class); 

    spec = tabHost 
      .newTabSpec("x") 
      .setIndicator("x", 


    tabHost.addTab(spec); 

    intent2 = new Intent().setClass(this, y.class); 
    spec = tabHost 
      .newTabSpec("y") 
      .setIndicator("y", 


    tabHost.addTab(spec); 

    intent3 = new Intent().setClass(this,z.class); 
    spec = tabHost 
      .newTabSpec("z") 
      .setIndicator("z", 


    tabHost.addTab(spec); 

    intent4 = new Intent().setClass(this, a.class); 
    spec = tabHost 
      .newTabSpec("a") 
      .setIndicator("a", 


    tabHost.addTab(spec); 

答えて

2

希望....

xmlファイル:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:admobsdk="http://schemas.android.com/apk/res/com.admob.android.example" 
    android:orientation="vertical"  
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 



<LinearLayout 
    android:id="@+id/llTab" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:visibility="visible" 
    android:layout_weight="2"> 

    <TabHost 
     android:id="@android:id/tabhost" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:focusable="false" 
     android:focusableInTouchMode="false"> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"     
      android:background="@android:color/darker_gray"    
      android:nextFocusUp="@android:id/tabcontent" 
      android:layout_gravity="bottom" 
      android:focusable="false" 
      android:focusableInTouchMode="false" 
      /> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:paddingBottom="65dp" 
      android:focusable="false" 
      android:focusableInTouchMode="false"/> 

    </TabHost> 

</LinearLayout> 

アクティビティ:

public class ActivityGroup extends TabActivity { 
/** Called when the activity is first created. */ 

    private static final String TAG_TYERS = "Tab1"; 
    private static final String TAG_BABES = "Tab2"; 
    private static final String TAG_TEAMS = "Tab3"; 
    private static final String TAG_EVENTS = "Tab4"; 
    TabHost tabHost; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    tabHost = getTabHost(); 

    tabHost.addTab(tabHost.newTabSpec("Tab1") 
     .setIndicator(TAG_TYERS) 
     .setContent(new Intent().setClass(this, Tab1.class))); 

    tabHost.addTab(tabHost.newTabSpec("Tab2") 
     .setIndicator(TAG_BABES) 
     .setContent(new Intent().setClass(this, Tab2.class))); 

    tabHost.addTab(tabHost.newTabSpec("Tab3") 
     .setIndicator(TAG_EVENTS) 
     .setContent(new Intent().setClass(this, Tab3.class))); 

    tabHost.addTab(tabHost.newTabSpec("Tab4") 
     .setIndicator(TAG_EVENTS) 
     .setContent(new Intent().setClass(this, Tab4.class))); 

    tabHost.setCurrentTab(0); 
}