2011-07-08 119 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值。

相关问题