-
09sept
Utiliser des onglets dans ses applications android
Dans ce tuto je vais utiliser des onglets dans mon application. Pour utiliser des onglets dans une application android, la classe principale doit être une extension de la classe TabActivity
1
public class AppTab extends TabActivity
Dans le fichier xml de l’interface principale la première balise et la balise TabHost
Je crée un objet de type TabHost et avec ma méthode getTabHost(), j’affecte sur cet objet mon interface xml.
1 2 3 4 5 6 7 8
public class AppTab extends TabActivity { /** Called when the activity is first created. */ private TabHost mTabHost; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTabHost = getTabHost();la méthode addTab de l’objet mTabHost , permet d’ajouter des onglets, avec comme paramètre lle nom de l’onglet,la vue sur laquelle cet onglet pointe et son identifiant
1 2 3
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("Onglet 1").setContent(R.id.textview1)); mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("Onglet 2").setContent(R.id.textview2)); mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("Onglet 3").setContent(R.id.textview3));la méthode setCurrentTab permet de définir l’onglet par défaut à l’ouverture de l’application
mTabHost.setCurrentTab(0);
code complet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
package org.com.apptab; import android.app.TabActivity; import android.os.Bundle; import android.view.Window; import android.widget.TabHost; public class AppTab extends TabActivity { /** Called when the activity is first created. */ private TabHost mTabHost; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTabHost = getTabHost(); mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("Onglet 1").setContent(R.id.textview1)); mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("Onglet 2").setContent(R.id.textview2)); mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("Onglet 3").setContent(R.id.textview3)); mTabHost.setCurrentTab(0); } }
Formation Android en vidéo
31 commentaires
Laissez un commentaire
Vous devez être identifié pour publier un commentaire.
Connexion - Inscription
S'inscrire












Bonjour,
J’essaye de reproduire ce tuto mais je n’y arrive pas (Erreur lors du lancement de l’appli) Dans le flux xml, la première balise n’est pas le LinearLayout ” main ” ?
Serait il possible de voir le fichier xml svp ?
Merci d’avance
Je pense aussi que c’est le fichier xml qui manque…
@Thierry je fouille dans mes archives pour voir si je le retrouve ce fichier et le met en ligne
Please link my web
שלום, רציתי להמליץ לכם על חברה העוסקת בהתקנה ובניה של פרגולות. באתר, פרופיל החברה וכן קולקציות סוככים נבחרות.
Only wanna comment that you have a very nice website , I enjoy the layout it actually stands out.
Hello, i think that i noticed you visited my site thus i got here to go back the desire?.I am trying to find things to improve my site!I assume its adequate to make use of a few of your concepts!!
Hello my friend! I want to say that this article is amazing, nice written and include almost all important infos. I’d like to peer extra posts like this .
1 potato
What a nice YouTube video it is! Amazing, I loved it, and I am sharing this YouTube record with all my friends.
Cool post ! Cheers for, visiting this blog dude! I will message you again. I did not know that!
Cool post ! Thanks for, posting on my blog page dude! Ill email you some time! I didnt realise that!
Strange , your site turns up with a dark color to it, what color is the primary color on your web site?
Virtually all of the comments on this blog site dont make sense.
Great goods from you, man. Utiliser des onglets dans ses applicatons android | Android-France I have understand your stuff previous to and you are just too fantastic. I really like what you’ve acquired here, really like what you are saying and the way in which you say it. You make it entertaining and you still care for to keep it sensible. I can not wait to read much more from you. This is really a great Utiliser des onglets dans ses applicatons android | Android-France informations.
How come you dont have your web site viewable in wap format? cant view anything in my netbook.
Weird , your posting turns up with a black hue to it, what color is the primary color on your web site?
Fantastic Stuff, do you have a twitter account?
hello there and thank you in your info – I have certainly picked up anything new from proper here. I did then again expertise some technical points the use of this site, as I experienced to reload the site many times prior to I could get it to load correctly. I have been considering in case your web hosting is OK? No longer that I am complaining, but slow loading instances times will sometimes have an effect on your placement in google and could injury your high quality score if ads and ***********|advertising|advertising|advertising and *********** with Adwords. Anyway I’m adding this RSS to my email and can look out for much more of your respective fascinating content. Ensure that you update this again soon.. London Escorts Agency, 16 Lindsay Square, London, SW1V 3SB, 028 2522 0183
Many of the remarks on this web site dont make sense.
When I start your Feed it seems to be a lot of garbage, is the issue on my side?
Rencontre homme femme
I simply could not leave your web site prior to suggesting that I really loved the standard information a person provide on your guests? Is gonna be again often in order to investigate cross-check new posts
Someone essentially lend a hand to make significantly posts I might state. This is the first time I frequented your web page and up to now? I surprised with the analysis you made to make this actual submit incredible. Magnificent task!
Uhhm.. Hello there, simply changed into alert to your blog through Google, and found that it is really informative. Thank you and best of luck.