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 :

remplacement de fragment


Sujet :

Android

  1. #1
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2012
    Messages
    149
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2012
    Messages : 149
    Points : 109
    Points
    109
    Par défaut remplacement de fragment
    Bonjour, j'ai un petit problème de fragment.

    j'ai un layout comme ça :

    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
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
     
       	<include layout="@layout/base_header" 
    		android:layout_width="fill_parent" 
    		android:layout_height="fill_parent"
    		android:layout_alignParentTop="true"
    		android:layout_alignParentLeft="true"
    		android:layout_marginTop="0dp"
    		android:layout_marginLeft="0dp"></include>
     
    	    <LinearLayout  android:layout_marginTop="50dp"
    		    android:layout_width="match_parent"
    		    android:layout_height="match_parent"
    		    android:orientation="horizontal"
    		    android:id="@+id/linear1">
     
    	        <LinearLayout android:layout_width="0dp"
    	            android:layout_height="match_parent"
    	            android:layout_weight="1">
    			   <fragment android:layout_width="match_parent"
    			        android:layout_height="match_parent"                                          android:name="package"    
                                    android:id = "@+id/list_fragment"/>
     
    	        </LinearLayout>
     
    	        <LinearLayout android:layout_width="0dp"
    	            android:layout_height="match_parent"
    	            android:layout_weight="3"
    		    android:id="@+id/detail_fragment">
     
    	        </LinearLayout>
     
    		</LinearLayout>
    </RelativeLayout>
    et j'essaye de remplacer (ou d'ajouter à) "detail_fragment" par un fragment dans mon code java, code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    			Fragment newFragment = new FragmentDetail();
    			ft.replace(R.id.detail_fragment, newFragment);
    			ft.addToBackStack(null);
    			ft.commit();
    le problème c'est que j'ai une exception qui me dit que le l'enfant spécifié à déjà un parent et qu'il faut que j'appel removeView() sur le parent d'abord.
    j'ai essayé un add a la place du replace ça me fait la même exception

    il y a quelque chose que je fais mal mais je vois pas quelqu'un à une idée?

  2. #2
    Membre éprouvé
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    757
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 757
    Points : 968
    Points
    968
    Par défaut
    Es-tu sûr que le problème vienne de là ? (et pas de l'instanciation du Fragment ?).

    Peux-tu nous écrire la stackTrace complète correspondante.

  3. #3
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2012
    Messages
    149
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2012
    Messages : 149
    Points : 109
    Points
    109
    Par défaut
    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
    07-24 10:15:42.358: E/AndroidRuntime(6146): FATAL EXCEPTION: main
    07-24 10:15:42.358: E/AndroidRuntime(6146): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at android.view.ViewGroup.addViewInner(ViewGroup.java:3339)
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at android.view.ViewGroup.addView(ViewGroup.java:3210)
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at android.view.ViewGroup.addView(ViewGroup.java:3155)
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at android.view.ViewGroup.addView(ViewGroup.java:3131)
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at android.support.v4.app.NoSaveStateFrameLayout.wrap(NoSaveStateFrameLayout.java:40)
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:915)
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at android.os.Handler.handleCallback(Handler.java:725)
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at android.os.Handler.dispatchMessage(Handler.java:92)
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at android.os.Looper.loop(Looper.java:137)
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at android.app.ActivityThread.main(ActivityThread.java:5041)
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at java.lang.reflect.Method.invokeNative(Native Method)
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at java.lang.reflect.Method.invoke(Method.java:511)
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    07-24 10:15:42.358: E/AndroidRuntime(6146): 	at dalvik.system.NativeStart.main(Native Method)

  4. #4
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2012
    Messages
    149
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2012
    Messages : 149
    Points : 109
    Points
    109
    Par défaut
    pour l'instaciation du fragment ça donne ça:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    public class FragmentDetail extends Fragment {
     
    	@Override
    	public View onCreateView(LayoutInflater inflater, ViewGroup container,
    			Bundle savedInstanceState) {
     
    		View mainView = inflater.inflate(R.layout.webcam_detail, container,true);
    		return mainView;
    	}
    }
    pour l'instant j'essaie juste de l'afficher pas de le remplir

  5. #5
    Membre éprouvé
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    757
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 757
    Points : 968
    Points
    968
    Par défaut
    La stackTrace n'est pas complète à mon avis.
    Sais-tu pourquoi tu as mis le paramètre 'true' dans la méthode inflate ?
    Essaie de faire ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    View mainView = inflater.inflate(R.layout.webcam_detail, container,true);
    		return mainView;
     
    //à remplacer par :
    return inflater.inflate(R.layout.webcam_detail, container,false);

  6. #6
    Membre régulier
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2012
    Messages
    149
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2012
    Messages : 149
    Points : 109
    Points
    109
    Par défaut
    c’était bien ça je sais pas pourquoi je l'ai mis a true surtout que j'ai d'autre projet de test et ils sont tous a false.

    Merci pour ton aide

  7. #7
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mai 2013
    Messages
    70
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Mai 2013
    Messages : 70
    Points : 113
    Points
    113
    Par défaut
    edite: ok mon message n'est pas utile

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

Discussions similaires

  1. Réponses: 0
    Dernier message: 04/09/2014, 22h46
  2. Réponses: 9
    Dernier message: 23/12/2013, 16h40
  3. Remplacer un fragment dans une chaine de caracteres
    Par VinceBassman dans le forum C++
    Réponses: 19
    Dernier message: 27/09/2006, 22h54
  4. comment remplacer une partie de texte dans un champs
    Par patlapi dans le forum Paradox
    Réponses: 4
    Dernier message: 20/11/2003, 14h38
  5. [SQL] Remplacer une table
    Par rstephane dans le forum Langage SQL
    Réponses: 5
    Dernier message: 06/05/2003, 17h10

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