2011-06-24 35 views
0

我想從一個標籤到另一個意圖..我該怎麼做? 我只有現在如何做活動之間。我需要從標籤到另一個..從一個標籤更改爲另一個

我有這個代碼的標籤

public class Main extends TabActivity 

{

@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 



    Resources res = getResources(); // Resource object to get Drawables 
     TabHost tabHost = getTabHost(); // The activity TabHost 
     TabHost.TabSpec spec; // Resusable TabSpec for each tab 
     Intent intent; // Reusable Intent for each tab 


     // Create an Intent to launch an Activity for the tab (to be reused) 
     //intent = new Intent().setClass(this, Contas.class); 
     Intent a = new Intent(Main.this, Contas.class); 
     Intent b = new Intent(Main.this, Registros.class); 
     Intent c = new Intent(Main.this, Relatorios.class); 
     // Initialize a TabSpec for each tab and add it to the TabHost 
     spec = tabHost.newTabSpec("Contas").setIndicator("Contas", 
          res.getDrawable(R.drawable.ic_tab_accounts)) 
         .setContent(a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); 
     tabHost.addTab(spec); 


     // Do the same for the other tabs 
     //intent = new Intent().setClass(this, Registros.class); 
     spec = tabHost.newTabSpec("Registros").setIndicator("Registros", 
          res.getDrawable(R.drawable.ic_tab_registry)) 
         .setContent(b.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); 
     tabHost.addTab(spec); 

     //intent = new Intent().setClass(this, Relatorios.class); 
     spec = tabHost.newTabSpec("Relatorios").setIndicator("Relatorios", 
          res.getDrawable(R.drawable.ic_tab_reports)) 
         .setContent(c.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); 
     tabHost.addTab(spec); 

     tabHost.setCurrentTab(0); 


} 

}

+0

你的問題是不明確的,你可以請詳細說明這個 – Dharmendra

回答

0

相反然後調用的意圖你可以設置所需的選項卡。 tabHost.setCurrentTab(index)

+0

這一點,如果我想在另一個活動 – jpmd

+0

然後把指數一個額外的參數的意圖和檢查,以不起作用在那個論點的活動中。如果可用,則選擇該選項卡。 –

+0

我不太明白..我該怎麼做? – jpmd

0

而不是調用意圖,你可以設置所需的選項卡選擇。 使用

intent.putExtra("tabIndex", index); 

,並調用活動。現在,在調用活動的onCreate()onResume()使用

int index = getIntent().getExtraInt("tabIndex", -1); 
if(index != -1) 
    tabHost.setCurrentTab(index); 
相關問題