2011-07-08 13 views
-1

私は3つのタブ(tab1、tab2、tab3)でアプリケーションを持っています。Tab1の一番下を押すと、どのようにtab2に移動できますか? 私は、これはあなたを助けるかもしれない....他のタブに移動

Resources res= getResources(); 
     TabHost tabHost= getTabHost(); 
     TabHost.TabSpec spec; 
     Intent intent; 

     // initialize a TabSpect for each tab and add it to the TabHost 
     intent= new Intent().setClass(this, StockMarket.class); 
     spec= tabHost.newTabSpec("1").setIndicator("Stock Market", res.getDrawable(R.drawable.grafica)) 
     .setContent(intent); 
     tabHost.addTab(spec); 

     intent= new Intent().setClass(this, Info.class); 
     spec= tabHost.newTabSpec("2").setIndicator("Data", res.getDrawable(R.drawable.puzzle)).setContent(intent); 
     tabHost.addTab(spec); 

     intent= new Intent().setClass(this, Profile.class); 
     spec= tabHost.newTabSpec("3").setIndicator("Profile", res.getDrawable(R.drawable.toolbox)).setContent(intent); 
     tabHost.addTab(spec); 

     intent= new Intent().setClass(this, Graphic.class); 
     spec= tabHost.newTabSpec("Graphic").setIndicator("Graphic", res.getDrawable(R.drawable.chart)).setContent(intent); 
     tabHost.addTab(spec); 

おかげ

答えて

-2

これを持っている -

getTabHost().setOnTabChangedListener(new OnTabChangeListener() { 

@Override 
public void onTabChanged(String tabId) { 

    int i = getTabHost().getCurrentTab(); 
    Log.i("TAB NUMBER", + i); 
    } 
}); 
1

はこれを試してみてください、それは私のために働きました。 はTabActivityはのは、その後、私のタブのアクティビティクラスを追加し、「MainActivity」

public TabHost getMyTabHost() { 
return tabHost; 
} 

それを呼びましょう拡張する私のメインクラスにメソッドを設定します。

MainActivity ta = (MainActivity) this.getParent(); 
TabHost t = ta.getMyTabHost(); 
t.setCurrentTab(0); 

setCurrentTab(0)でintにタブを設定できます。

関連する問題