2016-06-29 8 views
-1

私はタブのホストで3タブを持って、私はスイッチにしたい、この#ボタン1をクリックTab1を、現在よどうやってタブホストの別のタブに移動しますか?

TabSpec Tab1 = tabhost.newTabSpec("Tab1"); 
    jadwalUser.setIndicator("Tab1", getResources().getDrawable(R.drawable.style1)); 
    Intent in1 = new Intent(this, Tab1.class); 
    Tab1.setContent(in1); 

TabSpec Tab2 = tabhost.newTabSpec("Tab2"); 
Tab2.setIndicator("Tab2", getResources().getDrawable(R.drawable.style2)); 
Intent in2 = new Intent(this, Tab2.class); 
Tab2.setContent(in2); 

TabSpec Tab3 = tabhost.newTabSpec("Tab3"); 
Tab3.setIndicator("Tab3", getResources().getDrawable(R.drawable.style3)); 
Intent in3 = new Intent(this, Tab3.class); 
Tab3.setContent(in3); 

tabhost.addTab(Tab1); 
tabhost.addTab(Tab2); 
tabhost.addTab(Tab3);` 

button..`クリックで意図して別のタブに切り替えたいですTAB2に:

button1.setOnClickListener(new OnClickListener() { 

public void onClick(View v) { 
//What code here to switch to Tab2 

} 
} 

、私を助けてくださいありがとう..

+0

あなたは、活動や断片を切り替えるかどうか?あなたのタブには何が入っていますか? – PN10

+0

b/w fragments.Nothing now –

答えて

0

あなたはtabTagあなたはtabSpecを作成するために使用したのと同じ文字列であるTabHost.setCurrentTabByTag(tabTag)を、呼び出すことができます。したがって、あなたの例では、tab2に行くには:

tabhost.setCurrentTabByTag("Tab2"); 
関連する問題