2

I'm trying to insert a fragment to another and I’ve succeed to do this until I’ve lunch the main fragment for the first time it's working but when I’m trying to reload the fragment the app crash, and i have this error:

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

This is my 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

}

This is my 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>
Arjun saini
  • 4,223
  • 3
  • 23
  • 51
Rgv
  • 504
  • 5
  • 23
  • have you tried whats suggested in this 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 Jun 22 '16 at 07:14
  • ya,am already check it,but no use.here am using fragment in xml so its not working – Rgv Jun 22 '16 at 11:07
  • finally i realized,don't use fragment in fragment.So i shifted to PlaceAutocomplete Activity then solved my issue.Thank you for all support – Rgv Jun 23 '16 at 04:33

2 Answers2

7

I just ran into the same problem and could solve it by removing the fragment in the onDismiss callback.

@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();
    }
}
5

overide the onDestroyView method in the 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();
}

kotlin:

override fun onDestroyView() {
    super.onDestroyView()
    activity?.supportFragmentManager?.also { fragmentManager ->
        fragmentManager.findFragmentById(R.id.aboutFragment)?.also { fragment ->
            fragmentManager.beginTransaction().remove(fragment).commit()
        }
    }
}
Manish Jain
  • 2,139
  • 19
  • 15