2016-06-22 3 views
2

J'essaie d'insérer un fragment dans un autre et j'ai réussi à le faire jusqu'à ce que je déjeune le fragment principal pour le première fois qu'il fonctionne, mais quand je suis en train de recharger le fragment le crash de l'application, et j'ai cette erreur:Ligne de fichier XML binaire n ° 26: ID dupliqué, identificateur nul ou parent avec un autre fragment

Caused by: java.lang.IllegalArgumentException: Binary XML file line #26: 
Duplicate id 0x7f0e00e2, tag null, or parent id 0xffffffff with another 
fragment for com.google.android.gms.location.places.ui.PlaceAutocompleteFragment 

Ceci est mon fragment

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
Bundle savedInstanceState) { 

View rootView = inflater.inflate(R.layout.source_destination,container, false); 
PlaceAutocompleteFragment sourcr_autocompleteFragment = (PlaceAutocompleteFragment) 
      getActivity().getFragmentManager() 
.findFragmentById(R.id.sourcr_autocomplete_fragment); 
return rootView; 

// List item 

} 

Ceci est mon XML

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:padding="10dp" 
     android:background="@color/colorPrimary" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <android.support.v7.widget.CardView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="@dimen/margin_medium" 
      android:layout_marginBottom="@dimen/margin_medium"> 

      <fragment 
       android:id="@+id/sourcr_autocomplete_fragment"  
       android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"   
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 

     </android.support.v7.widget.CardView> 
    </LinearLayout> 
+0

avez-vous essayé ce qui est suggéré dans ce post? http://stackoverflow.com/questions/14083950/duplicate-id-tag-null-or-parent-id-with-another-fragment-for-com-google-androi?answertab=votes#tab-top – Dus

+0

ya , je suis déjà vérifier, mais pas d'utilisation.Il utilise fragment en xml donc son ne fonctionne pas – Rgv

+0

enfin je me suis rendu compte, ne pas utiliser le fragment dans le fragment.Alors je me suis déplacé à PlaceAutocomplete Activity alors résolu mon problème.Merci pour tout le soutien – Rgv

Répondre

3

overide la méthode onDestroyView dans le fragment

public void onDestroyView() { 
    super.onDestroyView(); 
    FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); 
    Fragment fragment = fragmentManager.findFragmentById(R.id.sourcr_autocomplete_fragment); 
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
    fragmentTransaction.remove(fragment); 
    fragmentTransaction.commit(); 
} 
+0

merci pour responde, j'ai déjà essayé mais pas de chance obtenir la même erreur – Rgv

3

Je viens de rencontrer le même problème et pourrait le résoudre en supprimant le fragment dans le rappel onDismiss.

@Override 
public void onDismiss(DialogInterface dialog) { 
    super.onDismiss(dialog); 

    if (getActivity() != null) { 
     FragmentManager fragmentManager = getActivity().getFragmentManager(); 
     Fragment fragment = fragmentManager.findFragmentById(R.id.sourcr_autocomplete_fragment); 
     FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
     fragmentTransaction.remove(fragment); 
     fragmentTransaction.commit(); 
    } 
}