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 :

BackStack ne fonctionne pas


Sujet :

Android

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    informatique, aikido
    Inscrit en
    Février 2014
    Messages
    42
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Espagne

    Informations professionnelles :
    Activité : informatique, aikido
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Février 2014
    Messages : 42
    Points : 32
    Points
    32
    Par défaut BackStack ne fonctionne pas
    Bonjour,

    Mon BackStack n'est pas effectif. Quand je clique sur retour, l'application se ferme.

    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
    package com.example.voyager6.lajares2;
     
    import android.app.Fragment;
    import android.app.FragmentManager;
    import android.app.FragmentTransaction;
    import android.support.v7.app.ActionBarActivity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.Button;
     
     
    public class MainActivity extends ActionBarActivity {
        Fragment fragment;
        Button btn1, btn2, btn3;
     
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            btn1 = (Button) findViewById(R.id.btn1);
            btn2 = (Button) findViewById(R.id.btn2);
            btn3 = (Button) findViewById(R.id.btn3);
     
            FragmentManager fm = getFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
     
            StartFragment myFragment = new StartFragment();
            ft.add(R.id.myFragment, myFragment);
            ft.commit();
     
            btn1.setOnClickListener(btnOnClickListener);
            btn2.setOnClickListener(btnOnClickListener);
            btn3.setOnClickListener(btnOnClickListener);
     
        }
     
        Button.OnClickListener btnOnClickListener = new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
     
                Fragment newFragment;
     
                if (v == btn1) {
                    newFragment = new Fragment1();
                } else if (v == btn2) {
                    newFragment = new Fragment2();
                } else if (v == btn3) {
                    newFragment = new Fragment3();
                } else {
                    newFragment = new StartFragment();
                }
     
                FragmentTransaction transaction = getFragmentManager().beginTransaction();
                transaction.replace(R.id.myFragment, newFragment);
                transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
                transaction.addToBackStack(null);
                transaction.commit();
            }
        };
    }
    Quelqu'un saurait-il m'indiquer d'où peut venir le problème ?

    Merci d'avance pour votre aide.
    Linux, xfce, ff, Android dev (éternel débutant).

  2. #2
    Candidat au Club
    Profil pro
    Inscrit en
    Novembre 2011
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2011
    Messages : 2
    Points : 2
    Points
    2
    Par défaut
    Bonjour,

    J'ai le même problème. Une solution ?

    Mon code pour afficher un fragment.
    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
    /*
     * Show fragment transaction
     */
    private void showFragment(final Fragment fragment) {
        if (fragment == null)
            return;
     
        final FragmentManager fm = getFragmentManager();
        final FragmentTransaction ft = fm.beginTransaction();
     
        // Replace current fragment by the new one.
        ft.replace(R.id.container_main, fragment);
        // Null on the back stack to return on the previous fragment when user
        // press on back button.
        ft.addToBackStack(null);
     
        ft.commit();
    }

  3. #3
    Membre régulier
    Homme Profil pro
    Ingénieur intégration
    Inscrit en
    Novembre 2014
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Val d'Oise (Île de France)

    Informations professionnelles :
    Activité : Ingénieur intégration

    Informations forums :
    Inscription : Novembre 2014
    Messages : 67
    Points : 86
    Points
    86
    Par défaut
    Salut,

    Je ne sais pas bien comment fonctionnent les fragments, mais que dis la logcat ?

  4. #4
    Candidat au Club
    Profil pro
    Inscrit en
    Novembre 2011
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2011
    Messages : 2
    Points : 2
    Points
    2
    Par défaut
    Rien.

    Pas d'erreur, pas de warning et pas d'info.

    Il passe correctement dans le onDestroyView quand je press le bouton "Back"

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Développeur en systèmes embarqués
    Inscrit en
    Août 2011
    Messages
    19
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vaucluse (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2011
    Messages : 19
    Points : 8
    Points
    8
    Par défaut
    idem quelqu'un a trouvé une solution

    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
     
    public void onNavigationDrawerItemSelected(int position) {
            // update the main content by replacing fragments
            fragmentManager = getFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
     
            switch (position + 1) {
                case 1 : fragmentTransaction.replace(R.id.container, RessourcesFragment.newInstance(2))
                        .commit();
                    break;
                case 2 :
                case 3 :
                case 5 :
                case 6 :
                case 7 : fragmentTransaction.replace(R.id.container, RessourcesFragment.newInstance(position + 1))
                        .commit();
                    break;
            }
     
        }
     
    public void afficherDetails (int section, String ref) {
            fragmentManager = getFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.container, EntitesDetailsFragment.newInstance(section, ref)).addToBackStack(null)
                    .commit();
        }
    merci d'avance

Discussions similaires

  1. Réponses: 6
    Dernier message: 27/01/2004, 11h14
  2. [FP]Writeln ne fonctionne pas !
    Par néo333 dans le forum Turbo Pascal
    Réponses: 4
    Dernier message: 01/11/2003, 23h47
  3. UNION qui ne fonctionne pas
    Par r-zo dans le forum Langage SQL
    Réponses: 7
    Dernier message: 21/07/2003, 10h04
  4. Un Hint sur un PopupMenu ne fonctionne pas !!??
    Par momox dans le forum C++Builder
    Réponses: 6
    Dernier message: 26/05/2003, 16h48
  5. ca ne fonctionne pas (generateur auto-incrémentant)
    Par tripper.dim dans le forum SQL
    Réponses: 7
    Dernier message: 26/11/2002, 00h10

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