2012-05-12 3 views
0

J'ai dans le suivant StartActivity CONTROLE DE ROTATION:Commutateur Taps de Activitys par des boutons, etc

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 


    TabHost tabHost = getTabHost(); 

    // Tab for A Tap 
    TabSpec atapspec = tabHost.newTabSpec("ATap"); 
    // setting Title and Icon for the Tab 
    atapespec.setIndicator("ATap", getResources().getDrawable(R.drawable.state_atap)); 
    Intent atapIntent = new Intent(this, ATapActivity.class); 
    atapspec.setContent(atapIntent); 

    // Tab for B Tap 
    TabSpec btapspec = tabHost.newTabSpec("BTap"); 
    btapspec.setIndicator("BTap", getResources().getDrawable(R.drawable.state_btap)); 
    Intent btapIntent = new Intent(this, BtapActivity.class); 
    btapspec.setContent(btapIntent); 



    // Adding all TabSpec to TabHost 
    tabHost.addTab(atapspec); // Adding a tab 
    tabHost.addTab(btapspec); // Adding b tab 


} 

Chaque robinet a sa propre activité. Maintenant, mon problème, comment puis-je passer d'un bouton à la prochaine activité Tap? J'ai essayé de démarrer uniquement l'activité, mais le contrôle Tap était manquant.

startActivity(new Intent(this, BTapActivity.class)); 

Je trouve qu'il devrait être sometion comme ça:

setCurrentTabByTag("BTab"); 

mais je ne sais pas comment.

EDIT:

Quand je mets "tabHost.setCurrentTabByTag (" BTAP ");" à la fin de la méthode onCreate, BTap est sélectionné. Par conséquent, il s'agit de la commande correcte. Mais à partir d'une autre activité, je ne suis pas en mesure d'accéder au tabHost. Quand je fais le le tabHost à un objet global, se bloque App:

TabHost tabHost = getTabHost(); 

Je l'ai essayé comme ceci à partir de l'onglet-activité:

startActivity StartAct = new startActivity(); 
StartAct.setTap("BTap"); 

Cette méthode est la StartActivity:

public void setTap(String tap) { 

    tabHost.setCurrentTabByTag(tap); 
} 

Que puis-je faire? Désolé, mais je suis un débutant ...

Répondre

0

Vous pouvez utiliser la fonction setCurrentTab(int index) de TabHost pour ouvrir les onglets par programmation.

+0

Merci, la seule chose qui me manquait était tabHost tabHost = (TabHost) findViewById (android.R.id.tabhost); – user1390816

Questions connexes