IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Problème affichage dans des onglets tabHost


Sujet :

Android

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    41
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 41
    Points : 34
    Points
    34
    Par défaut Problème affichage dans des onglets tabHost
    Bonjour,

    Je développe actuellement une application permettant d'afficher un emploi du temps. Mais j'ai un problème, lorsque je clique sur suivant pour afficher l'emploi du temps de la semaine suivante, la méthode creerOnglets() devrait afficher l'emploi du temps de la semaine suivante grâce aux variables date1erJourSemaine, date2emeJourSemaine... qui ont pris la valeur de la semaine suivante. Mais ici, quand je clique sur suivant j'ai l'impression que ma méthode creerOnglets() ne s'exécute pas alors qu'elle fonctionne très bien pour afficher l'edt de la semaine courante.

    Auriez-vous une idée d'où vient le problème?

    Voici mon code:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    package com.projet.EsaiPlanning;
     
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
     
    import android.app.TabActivity;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.Menu;
    import android.view.MenuInflater;
    import android.view.MenuItem;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.Spinner;
    import android.widget.TabHost;
    import android.widget.TabHost.TabSpec;
    import android.widget.TextView;
     
    public class DisplayEdtActivity extends TabActivity {
     
    	private TabHost tabHost; 
    	private TabSpec tabSpec;
    	private Button semaineSuiv;
    	private Button semainePrec;
    	private Calendar calendar;
    	private Date date1erJourSemaine;
    	private Date date2emeJourSemaine;
    	private Date date3emeJourSemaine;
    	private Date date4emeJourSemaine;
    	private Date date5emeJourSemaine;
    	private TextView texteSemaine;
    	private SimpleDateFormat dateFormat1;
    	private SimpleDateFormat dateFormat2;
     
     
     
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.fenetre_emploi_du_temps);
            calendar = Calendar.getInstance();
     
            dateFormat1 = new SimpleDateFormat("dd/MM");
            dateFormat2 = new SimpleDateFormat("dd/MM/yyyy");
     
            //détermination de la date du premier jour de la semaine (Lundi)
            calendar.set(Calendar.DAY_OF_WEEK, -5);
            date1erJourSemaine =calendar.getTime();
     
     
          //détermination de la date du deuxieme jour de la semaine (Mardi)
            calendar.set(Calendar.DAY_OF_WEEK, -4);
            date2emeJourSemaine =calendar.getTime();
     
     
          //détermination de la date du troisieme jour de la semaine (Mercredi)
            calendar.set(Calendar.DAY_OF_WEEK, -3);
            date3emeJourSemaine =calendar.getTime();
     
          //détermination de la date du quatrieme jour de la semaine (Jeudi)
            calendar.set(Calendar.DAY_OF_WEEK, -2);
            date4emeJourSemaine =calendar.getTime();
     
          //détermination de la date du cinquième jour de la semaine (Vendredi)
            calendar.set(Calendar.DAY_OF_WEEK, -1);
            date5emeJourSemaine =calendar.getTime();
     
            texteSemaine=(TextView) findViewById(R.id.semaine);
            texteSemaine.setText("Semaine du "+dateFormat1.format(date1erJourSemaine)+" au "+dateFormat1.format(date5emeJourSemaine));
     
     
            Spinner choixFormationBis = (Spinner) findViewById(R.id.choixFormationBis);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            adapter.add("IR1");
            adapter.add("IR2");
            adapter.add("IR3");
            adapter.add("SEP1");
            adapter.add("SEP2");
            adapter.add("SEP3");
            adapter.add("CPI1");
            adapter.add("CPI2");
            adapter.add("CPI3");
            choixFormationBis.setAdapter(adapter);
            Bundle objetbunble  = this.getIntent().getExtras(); 
            // récupération de la valeur
            String choix=objetbunble.getString("choix");
        	for (int i = 0; i < choixFormationBis.getCount(); i++) {
                String value = choixFormationBis.getItemAtPosition(i).toString();
                if (value.equals(choix)) {
                	choixFormationBis.setSelection(i);
                }
            }
        	creerOnglets();
     
            semainePrec = (Button) findViewById(R.id.semainePrec);
            semainePrec.setOnClickListener(new OnClickListener() { // création de la méthode dans la déclaration
    			public void onClick(View v) {
     
     
    				calendar.set(Calendar.WEEK_OF_YEAR,calendar.get(Calendar.WEEK_OF_YEAR)-1);
    				System.out.println("semaine : "+calendar.get(Calendar.WEEK_OF_YEAR));
    				//détermination de la date du premier jour de la semaine (Lundi)
    		        calendar.set(Calendar.DAY_OF_WEEK, -5);
    		        date1erJourSemaine =calendar.getTime();
     
    		      //détermination de la date du deuxieme jour de la semaine (Mardi)
    		        calendar.set(Calendar.DAY_OF_WEEK, -4);
    		        date2emeJourSemaine =calendar.getTime();
     
    		      //détermination de la date du troisieme jour de la semaine (Mercredi)
    		        calendar.set(Calendar.DAY_OF_WEEK, -3);
    		        date3emeJourSemaine =calendar.getTime();
     
    		      //détermination de la date du quatrieme jour de la semaine (Jeudi)
    		        calendar.set(Calendar.DAY_OF_WEEK, -2);
    		        date4emeJourSemaine =calendar.getTime();
     
    		      //détermination de la date du cinquième jour de la semaine (Vendredi)
    		        calendar.set(Calendar.DAY_OF_WEEK, -1);
    		        date5emeJourSemaine =calendar.getTime();
    		    	tabHost.setCurrentTab(0);
    		        tabHost.clearAllTabs();
    		        creerOnglets();
     
    		        texteSemaine.setText("Semaine du "+dateFormat1.format(date1erJourSemaine)+" au "+dateFormat1.format(date5emeJourSemaine));
    			}
    		});
     
     
            semaineSuiv = (Button) findViewById(R.id.semaineSuiv);
            semaineSuiv.setOnClickListener(new OnClickListener() { // création de la méthode dans la déclaration
    			public void onClick(View v) {
     
     
    		        calendar.set(Calendar.WEEK_OF_YEAR,calendar.get(Calendar.WEEK_OF_YEAR)+1);
    		        System.out.println("semaine : "+calendar.get(Calendar.WEEK_OF_YEAR));
    				//détermination de la date du premier jour de la semaine (Lundi)
    		        calendar.set(Calendar.DAY_OF_WEEK, -5);
    		        date1erJourSemaine =calendar.getTime();
    		      //détermination de la date du deuxieme jour de la semaine (Mardi)
    		        calendar.set(Calendar.DAY_OF_WEEK, -4);
    		        date2emeJourSemaine =calendar.getTime();
    		        System.out.println(date2emeJourSemaine);
     
    		      //détermination de la date du troisieme jour de la semaine (Mercredi)
    		        calendar.set(Calendar.DAY_OF_WEEK, -3);
    		        date3emeJourSemaine =calendar.getTime();
     
     
    		      //détermination de la date du quatrieme jour de la semaine (Jeudi)
    		        calendar.set(Calendar.DAY_OF_WEEK, -2);
    		        date4emeJourSemaine =calendar.getTime();
     
    		      //détermination de la date du cinquième jour de la semaine (Vendredi)
    		        calendar.set(Calendar.DAY_OF_WEEK, -1);
    		        date5emeJourSemaine =calendar.getTime();
    		    	tabHost.setCurrentTab(0);
    		        tabHost.clearAllTabs();
    		        creerOnglets();
     
    		        texteSemaine.setText("Semaine du "+dateFormat1.format(date1erJourSemaine)+" au "+dateFormat1.format(date5emeJourSemaine));
    			}
    		});
        }
     
        public boolean onCreateOptionsMenu(Menu menu) {
        	MenuInflater inflater = getMenuInflater();
        	inflater.inflate(R.layout.options_menu, menu);
        	return true;
        }
     
        public boolean onOptionsItemSelected(MenuItem item) {
        	switch (item.getItemId()) {
    	    	case R.id.credits:
    	    		Intent openStartingPoint1 = new Intent("com.projet.EsaiPlanning.CREDITSACTIVITY");
    				startActivity(openStartingPoint1);
    	    		return true;
    	    	case R.id.options:
    	    		Intent openStartingPoint2 = new Intent("com.projet.EsaiPlanning.OPTIONSACTIVITY");
    				startActivity(openStartingPoint2);
    	    		return true;
    	    	default:
    	    		return super.onOptionsItemSelected(item);
        	}
        }
     
     
        private void creerOnglets(){
     
     
        	Intent intent = new Intent(this, OngletsActivity.class);
     
        	tabHost = getTabHost();
     
     
            intent.putExtra("date",dateFormat2.format(date1erJourSemaine));
            tabSpec = tabHost.newTabSpec("lundi").setIndicator(createTabView(this, "Lundi")).setContent(intent);
            tabHost.addTab(tabSpec);
     
            intent = new Intent(this, OngletsActivity.class);
            intent.putExtra("date",dateFormat2.format(date2emeJourSemaine));
            tabSpec = tabHost.newTabSpec("mardi").setIndicator(createTabView(this, "Mardi")).setContent(intent);
            tabHost.addTab(tabSpec);
     
            intent = new Intent(this, OngletsActivity.class);
            intent.putExtra("date",dateFormat2.format(date3emeJourSemaine));
            tabSpec = tabHost.newTabSpec("mercredi").setIndicator(createTabView(this, "Mercredi")).setContent(intent);
            tabHost.addTab(tabSpec);
     
            intent = new Intent(this, OngletsActivity.class);
            intent.putExtra("date",dateFormat2.format(date4emeJourSemaine));
            tabSpec = tabHost.newTabSpec("jeudi").setIndicator(createTabView(this, "Jeudi")).setContent(intent);
            tabHost.addTab(tabSpec);
     
            intent = new Intent(this, OngletsActivity.class);
            intent.putExtra("date",dateFormat2.format(date5emeJourSemaine));
            tabSpec = tabHost.newTabSpec("vendredi").setIndicator(createTabView(this, "Vendredi")).setContent(intent);
            tabHost.addTab(tabSpec);
     
            Calendar cal = Calendar.getInstance();
            Date currentDay=cal.getTime();
            SimpleDateFormat dformat =new SimpleDateFormat("EEE");
            if((dformat.format(currentDay)).equals("Mon")){
            	tabHost.setCurrentTabByTag("lundi");
            }
            else if((dformat.format(currentDay)).equals("Tue")){
            	tabHost.setCurrentTabByTag("mardi");
            }
            else if((dformat.format(currentDay)).equals("Wed")){
            	tabHost.setCurrentTabByTag("mercredi");
            }
            else if((dformat.format(currentDay)).equals("Thu")){
            	tabHost.setCurrentTabByTag("jeudi");
            }
            else if((dformat.format(currentDay)).equals("Fri")){
            	tabHost.setCurrentTabByTag("vendredi");
            }
            else tabHost.setCurrentTabByTag("vendredi");
        }
     
     
    	private static View createTabView(final Context context, final String text) {
    		View view = LayoutInflater.from(context).inflate(R.layout.onglets_semaine, null);
    		TextView tv = (TextView) view.findViewById(R.id.contenu);
    		tv.setText(text);
    		return view;
    	}
     
    }

  2. #2
    Expert éminent

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Points : 9 149
    Points
    9 149
    Par défaut
    Bonjour,

    Pourrais tu nous poster tes logs ?

    Merci.
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

  3. #3
    Inscrit

    Profil pro
    Inscrit en
    Février 2008
    Messages
    658
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 658
    Points : 892
    Points
    892
    Par défaut
    Ton probleme pourrai venir par le fait que chaque Onglet ans une tabActivity doit etre associé à une classe qui s'etends de l'Activity!
    Je connais pas le resultat que tu attens mais tu repete "OngletsActivity.class"
    dans chaque host!
    Tu n'a qu'une seule intent qui encapsulte tout tes donnée; a chaque ajoute d'un host essaye d'associer un intent differente et une activity differente

    Comme je le fais dans ce qui suit:


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    private void creerOnglets(){
     
     
        	Intent intent =null;
     
        	tabHost = getTabHost();
     
     
            intent.putExtra("date",dateFormat2.format(date1erJourSemaine));
            tabSpec = tabHost.newTabSpec("lundi").setIndicator(createTabView(this, "Lundi")).setContent(intent);
            tabHost.addTab(tabSpec);
     
            intent = new Intent(this, OngletsActivity0.class);
            intent.putExtra("date",dateFormat2.format(date2emeJourSemaine));
            tabSpec = tabHost.newTabSpec("mardi").setIndicator(createTabView(this, "Mardi")).setContent(intent);
            tabHost.addTab(tabSpec);
     
            intent = new Intent(this, OngletsActivity1.class);
            intent.putExtra("date",dateFormat2.format(date3emeJourSemaine));
            tabSpec = tabHost.newTabSpec("mercredi").setIndicator(createTabView(this, "Mercredi")).setContent(intent);
            tabHost.addTab(tabSpec);
     
            intent = new Intent(this, OngletsActivity2.class);
            intent.putExtra("date",dateFormat2.format(date4emeJourSemaine));
            tabSpec = tabHost.newTabSpec("jeudi").setIndicator(createTabView(this, "Jeudi")).setContent(intent);
            tabHost.addTab(tabSpec);
     
            intent = new Intent(this, OngletsActivity3.class);
            intent.putExtra("date",dateFormat2.format(date5emeJourSemaine));
            tabSpec = tabHost.newTabSpec("vendredi").setIndicator(createTabView(this, "Vendredi")).setContent(intent);
            tabHost.addTab(tabSpec);
     
            Calendar cal = Calendar.getInstance();
            Date currentDay=cal.getTime();
            SimpleDateFormat dformat =new SimpleDateFormat("EEE");
            if((dformat.format(currentDay)).equals("Mon")){
            	tabHost.setCurrentTabByTag("lundi");
            }
            else if((dformat.format(currentDay)).equals("Tue")){
            	tabHost.setCurrentTabByTag("mardi");
            }
            else if((dformat.format(currentDay)).equals("Wed")){
            	tabHost.setCurrentTabByTag("mercredi");
            }
            else if((dformat.format(currentDay)).equals("Thu")){
            	tabHost.setCurrentTabByTag("jeudi");
            }
            else if((dformat.format(currentDay)).equals("Fri")){
            	tabHost.setCurrentTabByTag("vendredi");
            }
            else tabHost.setCurrentTabByTag("vendredi");
        }

  4. #4
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    41
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 41
    Points : 34
    Points
    34
    Par défaut
    Merci jahbromo, ta réponse m'a permis de résoudre mon problème

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 4
    Dernier message: 07/07/2015, 11h32
  2. Problème de boutons dans des onglets
    Par nicolav dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 08/07/2009, 10h33
  3. Réponses: 1
    Dernier message: 24/04/2009, 18h14
  4. Problème d'affichage dans des TScrollBox sous Windows Vista
    Par ILPlais dans le forum Composants VCL
    Réponses: 1
    Dernier message: 28/05/2008, 10h09
  5. CListCtrl dans des onglets
    Par BaBeuH dans le forum MFC
    Réponses: 3
    Dernier message: 13/06/2005, 12h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo