SlideShare une entreprise Scribd logo
1  sur  10
Développer sur Android
Android Lab Test
www.AndroidLabTest.com
Facebook
Par Bruno Delb
www.youtube.com/androidlabtest
www.twitter.com/brunodelb | www.facebook.com/brunodelb | blog.brunodelb.com
www.facebook.com/Androidlabtest
Youtube
Siteofficiel
Leçon : Le menu créé dynamiquement
Le menu créé dynamiquement
• Dans cette leçon, vous allez apprendre à créer un menu
dynamiquement.
• Pour cela, vous utilisez MenuItem et
onOptionsItemSelected.
Le menu créé dynamiquement
• Le menu doit être créé dans la méthode onCreateOptionsMenu().
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
...
return true;
}
• Pour sélectionner le mode du clavier (par exemple si vous utilisez
des raccourcis), utilisez la méthode setQwertyMode() :
menu.setQwertyMode(true);
Le menu créé dynamiquement
• Pour ajouter un élément au menu, utilisez la méthode add() :
MenuItem menuItem2 = menu.add(0, 1, 1, "Item 2");
• Pour ajouter un raccourci sur l’élément du menu, utilisez la méthode
setAlphabeticShortcut() :
menuItem2.setAlphabeticShortcut('b');
• Pour ajouter un icône à un élément du menu, utilisez la méthode
setIcon.
menuItem2.setIcon (R.drawable.app);
Le menu créé dynamiquement
• La méthode onOptionsItemSelected() est appelée à chaque
sélection d’un élément du menu avec en argument l’élément
sélectionné MenuItem.
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 0: // Item 1
return true;
case 1: // Item 2
return true;
}
return false;
}
Layout main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
Fichier Main.java
public class Main extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.setQwertyMode(true);
MenuItem menuItem1 = menu.add(0, 0, 0, "Item 1");
menuItem1.setAlphabeticShortcut('a');
MenuItem menuItem2 = menu.add(0, 1, 1, "Item 2");
menuItem2.setAlphabeticShortcut('b');
menuItem2.setIcon (R.drawable.app);
MenuItem menuItem3 = menu.add(0, 2, 2, "Item 3");
menuItem3.setAlphabeticShortcut('c');
return true;
}
Fichier Main.java
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 0:
Toast.makeText(this, "Item 1", Toast.LENGTH_LONG).show();
return true;
case 1:
Toast.makeText(this, "Item 2", Toast.LENGTH_LONG).show();
return true;
case 2:
Toast.makeText(this, "Item 3", Toast.LENGTH_LONG).show();
return true;
}
return false;
}
}
Testez sur votre mobile
View_Menu_Dynamic
Retrouvez-moi sur ma chaîne AndroidLabTest …
Sur ma chaîne Youtube
https://www.youtube.com/user/mobiledevlabtest
Qui suis-je ?
Bruno Delb,
auteur du 1er livre francophone de développement d’application Java sur mobile (2002),
développeur d’applications mobiles & sociales,
parlez-moi de vos projets.
Et bien sûr sur mon site Web :
http://blog.brunodelb.com

Contenu connexe

En vedette

Présentation sudrie 060215 v3b
Présentation sudrie 060215 v3bPrésentation sudrie 060215 v3b
Présentation sudrie 060215 v3bfwinet
 
Catalogo aldea 2013-14
Catalogo aldea 2013-14Catalogo aldea 2013-14
Catalogo aldea 2013-14maestrocurro
 
Beaute Sauvage
Beaute SauvageBeaute Sauvage
Beaute Sauvagevolpe3
 
fidel el kung fushaolin
fidel el kung fushaolinfidel el kung fushaolin
fidel el kung fushaolinfideluzcat
 
Webinaire - Adaptez votre contenu au mobile
Webinaire - Adaptez votre contenu au mobileWebinaire - Adaptez votre contenu au mobile
Webinaire - Adaptez votre contenu au mobileDialog Insight
 
Investigación Científica 9d
Investigación Científica 9dInvestigación Científica 9d
Investigación Científica 9dgueste1fb0ab
 
Laboratorio De Circuitos
Laboratorio De CircuitosLaboratorio De Circuitos
Laboratorio De Circuitosguesta678d8
 
L'essentiel de PwC en 10 points
L'essentiel de PwC en 10 pointsL'essentiel de PwC en 10 points
L'essentiel de PwC en 10 pointsPwC France
 
Convention GPV
Convention GPVConvention GPV
Convention GPVRouen
 
Medulas consorcio Plan Viabilidad
Medulas consorcio Plan ViabilidadMedulas consorcio Plan Viabilidad
Medulas consorcio Plan ViabilidadAgrupación Galicia
 
988 Feliz Ano Nuevo (Menudospeques Net)
988 Feliz Ano Nuevo (Menudospeques Net)988 Feliz Ano Nuevo (Menudospeques Net)
988 Feliz Ano Nuevo (Menudospeques Net)Alvaro
 
C:\Cema\Psicofarmacos
C:\Cema\PsicofarmacosC:\Cema\Psicofarmacos
C:\Cema\Psicofarmacosgueste2c1102
 
La EducacióN En Los Colegios Yina Paola Marlen Memo
La EducacióN En Los Colegios Yina Paola Marlen MemoLa EducacióN En Los Colegios Yina Paola Marlen Memo
La EducacióN En Los Colegios Yina Paola Marlen Memomemoguille
 
red ciudadana por el cumplimiento gubernamental de las cumbres
red ciudadana por el cumplimiento gubernamental de las cumbresred ciudadana por el cumplimiento gubernamental de las cumbres
red ciudadana por el cumplimiento gubernamental de las cumbresGobernabilidad
 
energia interna de la tierra
energia interna de la tierraenergia interna de la tierra
energia interna de la tierraLuis Suárez
 

En vedette (20)

Présentation sudrie 060215 v3b
Présentation sudrie 060215 v3bPrésentation sudrie 060215 v3b
Présentation sudrie 060215 v3b
 
Catalogo aldea 2013-14
Catalogo aldea 2013-14Catalogo aldea 2013-14
Catalogo aldea 2013-14
 
Los programas Conecta en la jornada Think Big
Los programas Conecta en la jornada Think BigLos programas Conecta en la jornada Think Big
Los programas Conecta en la jornada Think Big
 
Beaute Sauvage
Beaute SauvageBeaute Sauvage
Beaute Sauvage
 
fidel el kung fushaolin
fidel el kung fushaolinfidel el kung fushaolin
fidel el kung fushaolin
 
Webinaire - Adaptez votre contenu au mobile
Webinaire - Adaptez votre contenu au mobileWebinaire - Adaptez votre contenu au mobile
Webinaire - Adaptez votre contenu au mobile
 
Investigación Científica 9d
Investigación Científica 9dInvestigación Científica 9d
Investigación Científica 9d
 
Laboratorio De Circuitos
Laboratorio De CircuitosLaboratorio De Circuitos
Laboratorio De Circuitos
 
Ponencia uab. 9 de abril de 2010.
Ponencia uab. 9 de abril de 2010.Ponencia uab. 9 de abril de 2010.
Ponencia uab. 9 de abril de 2010.
 
Présentation1
Présentation1Présentation1
Présentation1
 
L'essentiel de PwC en 10 points
L'essentiel de PwC en 10 pointsL'essentiel de PwC en 10 points
L'essentiel de PwC en 10 points
 
Convention GPV
Convention GPVConvention GPV
Convention GPV
 
Trabajo Info
Trabajo InfoTrabajo Info
Trabajo Info
 
Medulas consorcio Plan Viabilidad
Medulas consorcio Plan ViabilidadMedulas consorcio Plan Viabilidad
Medulas consorcio Plan Viabilidad
 
Setup
SetupSetup
Setup
 
988 Feliz Ano Nuevo (Menudospeques Net)
988 Feliz Ano Nuevo (Menudospeques Net)988 Feliz Ano Nuevo (Menudospeques Net)
988 Feliz Ano Nuevo (Menudospeques Net)
 
C:\Cema\Psicofarmacos
C:\Cema\PsicofarmacosC:\Cema\Psicofarmacos
C:\Cema\Psicofarmacos
 
La EducacióN En Los Colegios Yina Paola Marlen Memo
La EducacióN En Los Colegios Yina Paola Marlen MemoLa EducacióN En Los Colegios Yina Paola Marlen Memo
La EducacióN En Los Colegios Yina Paola Marlen Memo
 
red ciudadana por el cumplimiento gubernamental de las cumbres
red ciudadana por el cumplimiento gubernamental de las cumbresred ciudadana por el cumplimiento gubernamental de las cumbres
red ciudadana por el cumplimiento gubernamental de las cumbres
 
energia interna de la tierra
energia interna de la tierraenergia interna de la tierra
energia interna de la tierra
 

Plus de Bruno Delb

Introduction to Swift (tutorial)
Introduction to Swift (tutorial)Introduction to Swift (tutorial)
Introduction to Swift (tutorial)Bruno Delb
 
Android Lab Test : Storage of data with SharedPreferences (english)
Android Lab Test : Storage of data with SharedPreferences (english)Android Lab Test : Storage of data with SharedPreferences (english)
Android Lab Test : Storage of data with SharedPreferences (english)Bruno Delb
 
Android Lab Test : Using the sensor gyroscope (english)
Android Lab Test : Using the sensor gyroscope (english)Android Lab Test : Using the sensor gyroscope (english)
Android Lab Test : Using the sensor gyroscope (english)Bruno Delb
 
Android Lab Test : Using the network with HTTP (english)
Android Lab Test : Using the network with HTTP (english)Android Lab Test : Using the network with HTTP (english)
Android Lab Test : Using the network with HTTP (english)Bruno Delb
 
Android Lab Test : Managing sounds with SoundPool (english)
Android Lab Test : Managing sounds with SoundPool (english)Android Lab Test : Managing sounds with SoundPool (english)
Android Lab Test : Managing sounds with SoundPool (english)Bruno Delb
 
Android Lab Test : Using the text-to-speech (english)
Android Lab Test : Using the text-to-speech (english)Android Lab Test : Using the text-to-speech (english)
Android Lab Test : Using the text-to-speech (english)Bruno Delb
 
Android Lab Test : Reading the foot file list (english)
Android Lab Test : Reading the foot file list (english)Android Lab Test : Reading the foot file list (english)
Android Lab Test : Reading the foot file list (english)Bruno Delb
 
Android Lab Test : Creating a menu dynamically (english)
Android Lab Test : Creating a menu dynamically (english)Android Lab Test : Creating a menu dynamically (english)
Android Lab Test : Creating a menu dynamically (english)Bruno Delb
 
Android Lab Test : Creating a dialog Yes/No (english)
Android Lab Test : Creating a dialog Yes/No (english)Android Lab Test : Creating a dialog Yes/No (english)
Android Lab Test : Creating a dialog Yes/No (english)Bruno Delb
 
Android Lab Test : The styles of views (english)
Android Lab Test : The styles of views (english)Android Lab Test : The styles of views (english)
Android Lab Test : The styles of views (english)Bruno Delb
 
Android Lab Test : Creating a menu context (english)
Android Lab Test : Creating a menu context (english)Android Lab Test : Creating a menu context (english)
Android Lab Test : Creating a menu context (english)Bruno Delb
 
Android Lab Test : Using the camera preview (english)
Android Lab Test : Using the camera preview (english)Android Lab Test : Using the camera preview (english)
Android Lab Test : Using the camera preview (english)Bruno Delb
 
Android Lab Test : The views, the Gallery (english)
Android Lab Test : The views, the Gallery (english)Android Lab Test : The views, the Gallery (english)
Android Lab Test : The views, the Gallery (english)Bruno Delb
 
Android Lab Test : Using the WIFI (english)
Android Lab Test : Using the WIFI (english)Android Lab Test : Using the WIFI (english)
Android Lab Test : Using the WIFI (english)Bruno Delb
 
Android Lab Test : Managing the telephone calls (english)
Android Lab Test : Managing the telephone calls (english)Android Lab Test : Managing the telephone calls (english)
Android Lab Test : Managing the telephone calls (english)Bruno Delb
 
Android Lab Test : Reading the SMS-inbox (english)
Android Lab Test : Reading the SMS-inbox (english)Android Lab Test : Reading the SMS-inbox (english)
Android Lab Test : Reading the SMS-inbox (english)Bruno Delb
 
Android Lab Test : Installation of application in Java (english)
Android Lab Test : Installation of application in Java (english)Android Lab Test : Installation of application in Java (english)
Android Lab Test : Installation of application in Java (english)Bruno Delb
 
Android Lab Test : Ecrire un texte sur le canevas (français)
Android Lab Test : Ecrire un texte sur le canevas (français)Android Lab Test : Ecrire un texte sur le canevas (français)
Android Lab Test : Ecrire un texte sur le canevas (français)Bruno Delb
 
Android Lab Test : La connectivité réseau avec HTTP (français)
Android Lab Test : La connectivité réseau avec HTTP (français)Android Lab Test : La connectivité réseau avec HTTP (français)
Android Lab Test : La connectivité réseau avec HTTP (français)Bruno Delb
 
Android Lab Test : Le capteur gyroscope (français)
Android Lab Test : Le capteur gyroscope (français)Android Lab Test : Le capteur gyroscope (français)
Android Lab Test : Le capteur gyroscope (français)Bruno Delb
 

Plus de Bruno Delb (20)

Introduction to Swift (tutorial)
Introduction to Swift (tutorial)Introduction to Swift (tutorial)
Introduction to Swift (tutorial)
 
Android Lab Test : Storage of data with SharedPreferences (english)
Android Lab Test : Storage of data with SharedPreferences (english)Android Lab Test : Storage of data with SharedPreferences (english)
Android Lab Test : Storage of data with SharedPreferences (english)
 
Android Lab Test : Using the sensor gyroscope (english)
Android Lab Test : Using the sensor gyroscope (english)Android Lab Test : Using the sensor gyroscope (english)
Android Lab Test : Using the sensor gyroscope (english)
 
Android Lab Test : Using the network with HTTP (english)
Android Lab Test : Using the network with HTTP (english)Android Lab Test : Using the network with HTTP (english)
Android Lab Test : Using the network with HTTP (english)
 
Android Lab Test : Managing sounds with SoundPool (english)
Android Lab Test : Managing sounds with SoundPool (english)Android Lab Test : Managing sounds with SoundPool (english)
Android Lab Test : Managing sounds with SoundPool (english)
 
Android Lab Test : Using the text-to-speech (english)
Android Lab Test : Using the text-to-speech (english)Android Lab Test : Using the text-to-speech (english)
Android Lab Test : Using the text-to-speech (english)
 
Android Lab Test : Reading the foot file list (english)
Android Lab Test : Reading the foot file list (english)Android Lab Test : Reading the foot file list (english)
Android Lab Test : Reading the foot file list (english)
 
Android Lab Test : Creating a menu dynamically (english)
Android Lab Test : Creating a menu dynamically (english)Android Lab Test : Creating a menu dynamically (english)
Android Lab Test : Creating a menu dynamically (english)
 
Android Lab Test : Creating a dialog Yes/No (english)
Android Lab Test : Creating a dialog Yes/No (english)Android Lab Test : Creating a dialog Yes/No (english)
Android Lab Test : Creating a dialog Yes/No (english)
 
Android Lab Test : The styles of views (english)
Android Lab Test : The styles of views (english)Android Lab Test : The styles of views (english)
Android Lab Test : The styles of views (english)
 
Android Lab Test : Creating a menu context (english)
Android Lab Test : Creating a menu context (english)Android Lab Test : Creating a menu context (english)
Android Lab Test : Creating a menu context (english)
 
Android Lab Test : Using the camera preview (english)
Android Lab Test : Using the camera preview (english)Android Lab Test : Using the camera preview (english)
Android Lab Test : Using the camera preview (english)
 
Android Lab Test : The views, the Gallery (english)
Android Lab Test : The views, the Gallery (english)Android Lab Test : The views, the Gallery (english)
Android Lab Test : The views, the Gallery (english)
 
Android Lab Test : Using the WIFI (english)
Android Lab Test : Using the WIFI (english)Android Lab Test : Using the WIFI (english)
Android Lab Test : Using the WIFI (english)
 
Android Lab Test : Managing the telephone calls (english)
Android Lab Test : Managing the telephone calls (english)Android Lab Test : Managing the telephone calls (english)
Android Lab Test : Managing the telephone calls (english)
 
Android Lab Test : Reading the SMS-inbox (english)
Android Lab Test : Reading the SMS-inbox (english)Android Lab Test : Reading the SMS-inbox (english)
Android Lab Test : Reading the SMS-inbox (english)
 
Android Lab Test : Installation of application in Java (english)
Android Lab Test : Installation of application in Java (english)Android Lab Test : Installation of application in Java (english)
Android Lab Test : Installation of application in Java (english)
 
Android Lab Test : Ecrire un texte sur le canevas (français)
Android Lab Test : Ecrire un texte sur le canevas (français)Android Lab Test : Ecrire un texte sur le canevas (français)
Android Lab Test : Ecrire un texte sur le canevas (français)
 
Android Lab Test : La connectivité réseau avec HTTP (français)
Android Lab Test : La connectivité réseau avec HTTP (français)Android Lab Test : La connectivité réseau avec HTTP (français)
Android Lab Test : La connectivité réseau avec HTTP (français)
 
Android Lab Test : Le capteur gyroscope (français)
Android Lab Test : Le capteur gyroscope (français)Android Lab Test : Le capteur gyroscope (français)
Android Lab Test : Le capteur gyroscope (français)
 

Dernier

RAPPORT DE STAGE D'INTERIM DE ATTIJARIWAFA BANK
RAPPORT DE STAGE D'INTERIM DE ATTIJARIWAFA BANKRAPPORT DE STAGE D'INTERIM DE ATTIJARIWAFA BANK
RAPPORT DE STAGE D'INTERIM DE ATTIJARIWAFA BANKNassimaMdh
 
Cours Généralités sur les systèmes informatiques
Cours Généralités sur les systèmes informatiquesCours Généralités sur les systèmes informatiques
Cours Généralités sur les systèmes informatiquesMohammedAmineHatoch
 
python-Cours Officiel POO Python-m103.pdf
python-Cours Officiel POO Python-m103.pdfpython-Cours Officiel POO Python-m103.pdf
python-Cours Officiel POO Python-m103.pdftrendingv83
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...Nguyen Thanh Tu Collection
 
L application de la physique classique dans le golf.pptx
L application de la physique classique dans le golf.pptxL application de la physique classique dans le golf.pptx
L application de la physique classique dans le golf.pptxhamzagame
 
Formation échiquéenne jwhyCHESS, parallèle avec la planification de projet
Formation échiquéenne jwhyCHESS, parallèle avec la planification de projetFormation échiquéenne jwhyCHESS, parallèle avec la planification de projet
Formation échiquéenne jwhyCHESS, parallèle avec la planification de projetJeanYvesMoine
 
Apolonia, Apolonia.pptx Film documentaire
Apolonia, Apolonia.pptx         Film documentaireApolonia, Apolonia.pptx         Film documentaire
Apolonia, Apolonia.pptx Film documentaireTxaruka
 
Intégration des TICE dans l'enseignement de la Physique-Chimie.pptx
Intégration des TICE dans l'enseignement de la Physique-Chimie.pptxIntégration des TICE dans l'enseignement de la Physique-Chimie.pptx
Intégration des TICE dans l'enseignement de la Physique-Chimie.pptxabdououanighd
 
Neuvaine de la Pentecôte avec des textes de saint Jean Eudes
Neuvaine de la Pentecôte avec des textes de saint Jean EudesNeuvaine de la Pentecôte avec des textes de saint Jean Eudes
Neuvaine de la Pentecôte avec des textes de saint Jean EudesUnidad de Espiritualidad Eudista
 
Copie de Engineering Software Marketing Plan by Slidesgo.pptx.pptx
Copie de Engineering Software Marketing Plan by Slidesgo.pptx.pptxCopie de Engineering Software Marketing Plan by Slidesgo.pptx.pptx
Copie de Engineering Software Marketing Plan by Slidesgo.pptx.pptxikospam0
 
les_infections_a_streptocoques.pptkioljhk
les_infections_a_streptocoques.pptkioljhkles_infections_a_streptocoques.pptkioljhk
les_infections_a_streptocoques.pptkioljhkRefRama
 
Bilan énergétique des chambres froides.pdf
Bilan énergétique des chambres froides.pdfBilan énergétique des chambres froides.pdf
Bilan énergétique des chambres froides.pdfAmgdoulHatim
 
L'expression du but : fiche et exercices niveau C1 FLE
L'expression du but : fiche et exercices  niveau C1 FLEL'expression du but : fiche et exercices  niveau C1 FLE
L'expression du but : fiche et exercices niveau C1 FLElebaobabbleu
 
CompLit - Journal of European Literature, Arts and Society - n. 7 - Table of ...
CompLit - Journal of European Literature, Arts and Society - n. 7 - Table of ...CompLit - Journal of European Literature, Arts and Society - n. 7 - Table of ...
CompLit - Journal of European Literature, Arts and Society - n. 7 - Table of ...Universidad Complutense de Madrid
 
Télécommunication et transport .pdfcours
Télécommunication et transport .pdfcoursTélécommunication et transport .pdfcours
Télécommunication et transport .pdfcourshalima98ahlmohamed
 

Dernier (16)

RAPPORT DE STAGE D'INTERIM DE ATTIJARIWAFA BANK
RAPPORT DE STAGE D'INTERIM DE ATTIJARIWAFA BANKRAPPORT DE STAGE D'INTERIM DE ATTIJARIWAFA BANK
RAPPORT DE STAGE D'INTERIM DE ATTIJARIWAFA BANK
 
Cours Généralités sur les systèmes informatiques
Cours Généralités sur les systèmes informatiquesCours Généralités sur les systèmes informatiques
Cours Généralités sur les systèmes informatiques
 
python-Cours Officiel POO Python-m103.pdf
python-Cours Officiel POO Python-m103.pdfpython-Cours Officiel POO Python-m103.pdf
python-Cours Officiel POO Python-m103.pdf
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI DẠY BUỔI 2) - TIẾNG ANH 6, 7 GLOBAL SUCCESS (2...
 
Echos libraries Burkina Faso newsletter 2024
Echos libraries Burkina Faso newsletter 2024Echos libraries Burkina Faso newsletter 2024
Echos libraries Burkina Faso newsletter 2024
 
L application de la physique classique dans le golf.pptx
L application de la physique classique dans le golf.pptxL application de la physique classique dans le golf.pptx
L application de la physique classique dans le golf.pptx
 
Formation échiquéenne jwhyCHESS, parallèle avec la planification de projet
Formation échiquéenne jwhyCHESS, parallèle avec la planification de projetFormation échiquéenne jwhyCHESS, parallèle avec la planification de projet
Formation échiquéenne jwhyCHESS, parallèle avec la planification de projet
 
Apolonia, Apolonia.pptx Film documentaire
Apolonia, Apolonia.pptx         Film documentaireApolonia, Apolonia.pptx         Film documentaire
Apolonia, Apolonia.pptx Film documentaire
 
Intégration des TICE dans l'enseignement de la Physique-Chimie.pptx
Intégration des TICE dans l'enseignement de la Physique-Chimie.pptxIntégration des TICE dans l'enseignement de la Physique-Chimie.pptx
Intégration des TICE dans l'enseignement de la Physique-Chimie.pptx
 
Neuvaine de la Pentecôte avec des textes de saint Jean Eudes
Neuvaine de la Pentecôte avec des textes de saint Jean EudesNeuvaine de la Pentecôte avec des textes de saint Jean Eudes
Neuvaine de la Pentecôte avec des textes de saint Jean Eudes
 
Copie de Engineering Software Marketing Plan by Slidesgo.pptx.pptx
Copie de Engineering Software Marketing Plan by Slidesgo.pptx.pptxCopie de Engineering Software Marketing Plan by Slidesgo.pptx.pptx
Copie de Engineering Software Marketing Plan by Slidesgo.pptx.pptx
 
les_infections_a_streptocoques.pptkioljhk
les_infections_a_streptocoques.pptkioljhkles_infections_a_streptocoques.pptkioljhk
les_infections_a_streptocoques.pptkioljhk
 
Bilan énergétique des chambres froides.pdf
Bilan énergétique des chambres froides.pdfBilan énergétique des chambres froides.pdf
Bilan énergétique des chambres froides.pdf
 
L'expression du but : fiche et exercices niveau C1 FLE
L'expression du but : fiche et exercices  niveau C1 FLEL'expression du but : fiche et exercices  niveau C1 FLE
L'expression du but : fiche et exercices niveau C1 FLE
 
CompLit - Journal of European Literature, Arts and Society - n. 7 - Table of ...
CompLit - Journal of European Literature, Arts and Society - n. 7 - Table of ...CompLit - Journal of European Literature, Arts and Society - n. 7 - Table of ...
CompLit - Journal of European Literature, Arts and Society - n. 7 - Table of ...
 
Télécommunication et transport .pdfcours
Télécommunication et transport .pdfcoursTélécommunication et transport .pdfcours
Télécommunication et transport .pdfcours
 

Android Lab Test : Le menu dynamique (français)

  • 1. Développer sur Android Android Lab Test www.AndroidLabTest.com Facebook Par Bruno Delb www.youtube.com/androidlabtest www.twitter.com/brunodelb | www.facebook.com/brunodelb | blog.brunodelb.com www.facebook.com/Androidlabtest Youtube Siteofficiel Leçon : Le menu créé dynamiquement
  • 2. Le menu créé dynamiquement • Dans cette leçon, vous allez apprendre à créer un menu dynamiquement. • Pour cela, vous utilisez MenuItem et onOptionsItemSelected.
  • 3. Le menu créé dynamiquement • Le menu doit être créé dans la méthode onCreateOptionsMenu(). public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); ... return true; } • Pour sélectionner le mode du clavier (par exemple si vous utilisez des raccourcis), utilisez la méthode setQwertyMode() : menu.setQwertyMode(true);
  • 4. Le menu créé dynamiquement • Pour ajouter un élément au menu, utilisez la méthode add() : MenuItem menuItem2 = menu.add(0, 1, 1, "Item 2"); • Pour ajouter un raccourci sur l’élément du menu, utilisez la méthode setAlphabeticShortcut() : menuItem2.setAlphabeticShortcut('b'); • Pour ajouter un icône à un élément du menu, utilisez la méthode setIcon. menuItem2.setIcon (R.drawable.app);
  • 5. Le menu créé dynamiquement • La méthode onOptionsItemSelected() est appelée à chaque sélection d’un élément du menu avec en argument l’élément sélectionné MenuItem. public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case 0: // Item 1 return true; case 1: // Item 2 return true; } return false; }
  • 6. Layout main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> </LinearLayout>
  • 7. Fichier Main.java public class Main extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); menu.setQwertyMode(true); MenuItem menuItem1 = menu.add(0, 0, 0, "Item 1"); menuItem1.setAlphabeticShortcut('a'); MenuItem menuItem2 = menu.add(0, 1, 1, "Item 2"); menuItem2.setAlphabeticShortcut('b'); menuItem2.setIcon (R.drawable.app); MenuItem menuItem3 = menu.add(0, 2, 2, "Item 3"); menuItem3.setAlphabeticShortcut('c'); return true; }
  • 8. Fichier Main.java public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case 0: Toast.makeText(this, "Item 1", Toast.LENGTH_LONG).show(); return true; case 1: Toast.makeText(this, "Item 2", Toast.LENGTH_LONG).show(); return true; case 2: Toast.makeText(this, "Item 3", Toast.LENGTH_LONG).show(); return true; } return false; } }
  • 9. Testez sur votre mobile View_Menu_Dynamic
  • 10. Retrouvez-moi sur ma chaîne AndroidLabTest … Sur ma chaîne Youtube https://www.youtube.com/user/mobiledevlabtest Qui suis-je ? Bruno Delb, auteur du 1er livre francophone de développement d’application Java sur mobile (2002), développeur d’applications mobiles & sociales, parlez-moi de vos projets. Et bien sûr sur mon site Web : http://blog.brunodelb.com