SlideShare a Scribd company logo
1 of 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

More Related Content

Viewers also liked

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
 

Viewers also liked (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
 

More from 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
 

More from 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)
 

Recently uploaded

SciencesPo_Aix_InnovationPédagogique_Atelier_EtudiantActeur.pdf
SciencesPo_Aix_InnovationPédagogique_Atelier_EtudiantActeur.pdfSciencesPo_Aix_InnovationPédagogique_Atelier_EtudiantActeur.pdf
SciencesPo_Aix_InnovationPédagogique_Atelier_EtudiantActeur.pdfSKennel
 
PIE-A2-P 5- Supports stagiaires.pptx.pdf
PIE-A2-P 5- Supports stagiaires.pptx.pdfPIE-A2-P 5- Supports stagiaires.pptx.pdf
PIE-A2-P 5- Supports stagiaires.pptx.pdfRiDaHAziz
 
SciencesPo_Aix_InnovationPédagogique_Conférence_SK.pdf
SciencesPo_Aix_InnovationPédagogique_Conférence_SK.pdfSciencesPo_Aix_InnovationPédagogique_Conférence_SK.pdf
SciencesPo_Aix_InnovationPédagogique_Conférence_SK.pdfSKennel
 
Zotero avancé - support de formation doctorants SHS 2024
Zotero avancé - support de formation doctorants SHS 2024Zotero avancé - support de formation doctorants SHS 2024
Zotero avancé - support de formation doctorants SHS 2024Alain Marois
 
Bernard Réquichot.pptx Peintre français
Bernard Réquichot.pptx   Peintre françaisBernard Réquichot.pptx   Peintre français
Bernard Réquichot.pptx Peintre françaisTxaruka
 
Cours SE Gestion des périphériques - IG IPSET
Cours SE Gestion des périphériques - IG IPSETCours SE Gestion des périphériques - IG IPSET
Cours SE Gestion des périphériques - IG IPSETMedBechir
 
SciencesPo_Aix_InnovationPédagogique_Atelier_IA.pdf
SciencesPo_Aix_InnovationPédagogique_Atelier_IA.pdfSciencesPo_Aix_InnovationPédagogique_Atelier_IA.pdf
SciencesPo_Aix_InnovationPédagogique_Atelier_IA.pdfSKennel
 
Le Lean sur une ligne de production : Formation et mise en application directe
Le Lean sur une ligne de production : Formation et mise en application directeLe Lean sur une ligne de production : Formation et mise en application directe
Le Lean sur une ligne de production : Formation et mise en application directeXL Groupe
 
Bibdoc 2024 - Les maillons de la chaine du livre face aux enjeux écologiques.pdf
Bibdoc 2024 - Les maillons de la chaine du livre face aux enjeux écologiques.pdfBibdoc 2024 - Les maillons de la chaine du livre face aux enjeux écologiques.pdf
Bibdoc 2024 - Les maillons de la chaine du livre face aux enjeux écologiques.pdfBibdoc 37
 
SciencesPo_Aix_InnovationPédagogique_Bilan.pdf
SciencesPo_Aix_InnovationPédagogique_Bilan.pdfSciencesPo_Aix_InnovationPédagogique_Bilan.pdf
SciencesPo_Aix_InnovationPédagogique_Bilan.pdfSKennel
 
Bibdoc 2024 - Ecologie du livre et creation de badge.pdf
Bibdoc 2024 - Ecologie du livre et creation de badge.pdfBibdoc 2024 - Ecologie du livre et creation de badge.pdf
Bibdoc 2024 - Ecologie du livre et creation de badge.pdfBibdoc 37
 
Presentation de la plateforme Moodle - avril 2024
Presentation de la plateforme Moodle - avril 2024Presentation de la plateforme Moodle - avril 2024
Presentation de la plateforme Moodle - avril 2024Gilles Le Page
 
LA MONTÉE DE L'ÉDUCATION DANS LE MONDE DE LA PRÉHISTOIRE À L'ÈRE CONTEMPORAIN...
LA MONTÉE DE L'ÉDUCATION DANS LE MONDE DE LA PRÉHISTOIRE À L'ÈRE CONTEMPORAIN...LA MONTÉE DE L'ÉDUCATION DANS LE MONDE DE LA PRÉHISTOIRE À L'ÈRE CONTEMPORAIN...
LA MONTÉE DE L'ÉDUCATION DANS LE MONDE DE LA PRÉHISTOIRE À L'ÈRE CONTEMPORAIN...Faga1939
 
Cours SE Le système Linux : La ligne de commande bash - IG IPSET
Cours SE Le système Linux : La ligne de commande bash - IG IPSETCours SE Le système Linux : La ligne de commande bash - IG IPSET
Cours SE Le système Linux : La ligne de commande bash - IG IPSETMedBechir
 
Principe de fonctionnement d'un moteur 4 temps
Principe de fonctionnement d'un moteur 4 tempsPrincipe de fonctionnement d'un moteur 4 temps
Principe de fonctionnement d'un moteur 4 tempsRajiAbdelghani
 
PIE-A2-P4-support stagiaires sept 22-validé.pdf
PIE-A2-P4-support stagiaires sept 22-validé.pdfPIE-A2-P4-support stagiaires sept 22-validé.pdf
PIE-A2-P4-support stagiaires sept 22-validé.pdfRiDaHAziz
 
Cours de Management des Systèmes d'information
Cours de Management des Systèmes d'informationCours de Management des Systèmes d'information
Cours de Management des Systèmes d'informationpapediallo3
 
Annie Ernaux Extérieurs. pptx. Exposition basée sur un livre .
Annie   Ernaux  Extérieurs. pptx. Exposition basée sur un livre .Annie   Ernaux  Extérieurs. pptx. Exposition basée sur un livre .
Annie Ernaux Extérieurs. pptx. Exposition basée sur un livre .Txaruka
 
SciencesPo_Aix_InnovationPédagogique_Atelier_FormationRecherche.pdf
SciencesPo_Aix_InnovationPédagogique_Atelier_FormationRecherche.pdfSciencesPo_Aix_InnovationPédagogique_Atelier_FormationRecherche.pdf
SciencesPo_Aix_InnovationPédagogique_Atelier_FormationRecherche.pdfSKennel
 

Recently uploaded (20)

SciencesPo_Aix_InnovationPédagogique_Atelier_EtudiantActeur.pdf
SciencesPo_Aix_InnovationPédagogique_Atelier_EtudiantActeur.pdfSciencesPo_Aix_InnovationPédagogique_Atelier_EtudiantActeur.pdf
SciencesPo_Aix_InnovationPédagogique_Atelier_EtudiantActeur.pdf
 
PIE-A2-P 5- Supports stagiaires.pptx.pdf
PIE-A2-P 5- Supports stagiaires.pptx.pdfPIE-A2-P 5- Supports stagiaires.pptx.pdf
PIE-A2-P 5- Supports stagiaires.pptx.pdf
 
DO PALÁCIO À ASSEMBLEIA .
DO PALÁCIO À ASSEMBLEIA                 .DO PALÁCIO À ASSEMBLEIA                 .
DO PALÁCIO À ASSEMBLEIA .
 
SciencesPo_Aix_InnovationPédagogique_Conférence_SK.pdf
SciencesPo_Aix_InnovationPédagogique_Conférence_SK.pdfSciencesPo_Aix_InnovationPédagogique_Conférence_SK.pdf
SciencesPo_Aix_InnovationPédagogique_Conférence_SK.pdf
 
Zotero avancé - support de formation doctorants SHS 2024
Zotero avancé - support de formation doctorants SHS 2024Zotero avancé - support de formation doctorants SHS 2024
Zotero avancé - support de formation doctorants SHS 2024
 
Bernard Réquichot.pptx Peintre français
Bernard Réquichot.pptx   Peintre françaisBernard Réquichot.pptx   Peintre français
Bernard Réquichot.pptx Peintre français
 
Cours SE Gestion des périphériques - IG IPSET
Cours SE Gestion des périphériques - IG IPSETCours SE Gestion des périphériques - IG IPSET
Cours SE Gestion des périphériques - IG IPSET
 
SciencesPo_Aix_InnovationPédagogique_Atelier_IA.pdf
SciencesPo_Aix_InnovationPédagogique_Atelier_IA.pdfSciencesPo_Aix_InnovationPédagogique_Atelier_IA.pdf
SciencesPo_Aix_InnovationPédagogique_Atelier_IA.pdf
 
Le Lean sur une ligne de production : Formation et mise en application directe
Le Lean sur une ligne de production : Formation et mise en application directeLe Lean sur une ligne de production : Formation et mise en application directe
Le Lean sur une ligne de production : Formation et mise en application directe
 
Bibdoc 2024 - Les maillons de la chaine du livre face aux enjeux écologiques.pdf
Bibdoc 2024 - Les maillons de la chaine du livre face aux enjeux écologiques.pdfBibdoc 2024 - Les maillons de la chaine du livre face aux enjeux écologiques.pdf
Bibdoc 2024 - Les maillons de la chaine du livre face aux enjeux écologiques.pdf
 
SciencesPo_Aix_InnovationPédagogique_Bilan.pdf
SciencesPo_Aix_InnovationPédagogique_Bilan.pdfSciencesPo_Aix_InnovationPédagogique_Bilan.pdf
SciencesPo_Aix_InnovationPédagogique_Bilan.pdf
 
Bibdoc 2024 - Ecologie du livre et creation de badge.pdf
Bibdoc 2024 - Ecologie du livre et creation de badge.pdfBibdoc 2024 - Ecologie du livre et creation de badge.pdf
Bibdoc 2024 - Ecologie du livre et creation de badge.pdf
 
Presentation de la plateforme Moodle - avril 2024
Presentation de la plateforme Moodle - avril 2024Presentation de la plateforme Moodle - avril 2024
Presentation de la plateforme Moodle - avril 2024
 
LA MONTÉE DE L'ÉDUCATION DANS LE MONDE DE LA PRÉHISTOIRE À L'ÈRE CONTEMPORAIN...
LA MONTÉE DE L'ÉDUCATION DANS LE MONDE DE LA PRÉHISTOIRE À L'ÈRE CONTEMPORAIN...LA MONTÉE DE L'ÉDUCATION DANS LE MONDE DE LA PRÉHISTOIRE À L'ÈRE CONTEMPORAIN...
LA MONTÉE DE L'ÉDUCATION DANS LE MONDE DE LA PRÉHISTOIRE À L'ÈRE CONTEMPORAIN...
 
Cours SE Le système Linux : La ligne de commande bash - IG IPSET
Cours SE Le système Linux : La ligne de commande bash - IG IPSETCours SE Le système Linux : La ligne de commande bash - IG IPSET
Cours SE Le système Linux : La ligne de commande bash - IG IPSET
 
Principe de fonctionnement d'un moteur 4 temps
Principe de fonctionnement d'un moteur 4 tempsPrincipe de fonctionnement d'un moteur 4 temps
Principe de fonctionnement d'un moteur 4 temps
 
PIE-A2-P4-support stagiaires sept 22-validé.pdf
PIE-A2-P4-support stagiaires sept 22-validé.pdfPIE-A2-P4-support stagiaires sept 22-validé.pdf
PIE-A2-P4-support stagiaires sept 22-validé.pdf
 
Cours de Management des Systèmes d'information
Cours de Management des Systèmes d'informationCours de Management des Systèmes d'information
Cours de Management des Systèmes d'information
 
Annie Ernaux Extérieurs. pptx. Exposition basée sur un livre .
Annie   Ernaux  Extérieurs. pptx. Exposition basée sur un livre .Annie   Ernaux  Extérieurs. pptx. Exposition basée sur un livre .
Annie Ernaux Extérieurs. pptx. Exposition basée sur un livre .
 
SciencesPo_Aix_InnovationPédagogique_Atelier_FormationRecherche.pdf
SciencesPo_Aix_InnovationPédagogique_Atelier_FormationRecherche.pdfSciencesPo_Aix_InnovationPédagogique_Atelier_FormationRecherche.pdf
SciencesPo_Aix_InnovationPédagogique_Atelier_FormationRecherche.pdf
 

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