2011-07-08 57 views
-1

我有一個應用程序與3選項卡(tab1,tab2,tab3)如何移動到tab2如果按tab1中的底部。 我有這個....移動到其他選項卡

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值。

相關問題