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);
}
} |




















15 février 2010 à 21 h 21 min
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
17 février 2010 à 18 h 04 min
Je pense aussi que c’est le fichier xml qui manque…
17 février 2010 à 18 h 13 min
@Thierry je fouille dans mes archives pour voir si je le retrouve ce fichier et le met en ligne
18 mai 2011 à 12 h 04 min
Please link my web
16 novembre 2011 à 21 h 02 min
שלום, רציתי להמליץ לכם על חברה העוסקת בהתקנה ובניה של פרגולות. באתר, פרופיל החברה וכן קולקציות סוככים נבחרות.
30 novembre 2011 à 17 h 19 min
Only wanna comment that you have a very nice website , I enjoy the layout it actually stands out.
13 décembre 2011 à 12 h 21 min
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!!
24 décembre 2011 à 13 h 38 min
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 .
05 janvier 2012 à 5 h 47 min
1 potato
10 janvier 2012 à 4 h 25 min
What a nice YouTube video it is! Amazing, I loved it, and I am sharing this YouTube record with all my friends.
11 janvier 2012 à 16 h 30 min
Cool post ! Cheers for, visiting this blog dude! I will message you again. I did not know that!
16 janvier 2012 à 23 h 27 min
Cool post ! Thanks for, posting on my blog page dude! Ill email you some time! I didnt realise that!
20 janvier 2012 à 7 h 24 min
Strange , your site turns up with a dark color to it, what color is the primary color on your web site?
26 janvier 2012 à 9 h 08 min
Virtually all of the comments on this blog site dont make sense.
28 janvier 2012 à 6 h 43 min
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.
31 janvier 2012 à 6 h 32 min
How come you dont have your web site viewable in wap format? cant view anything in my netbook.
07 février 2012 à 8 h 56 min
Weird , your posting turns up with a black hue to it, what color is the primary color on your web site?
07 février 2012 à 18 h 54 min
Fantastic Stuff, do you have a twitter account?
07 février 2012 à 19 h 52 min
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