I am using PlaceAutoCompleteFragment
inside a Fragment. First time when Fragment
(App fragment in which PlaceAutoCompleteFragment
is placed) opens it works fine like a charm. But, then second time I hit button to open Fragment it crashes with below error. It works only a single time.
FATAL EXCEPTION:
android.view.InflateException: Binary XML file line #64: Error inflating class fragment
Caused by: java.lang.IllegalArgumentException: Binary XML file line #64: Duplicate id 0x7f0d0094, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.location.places.ui.PlaceAutocompleteFragment
This is how i am using this:
SupportPlaceAutocompleteFragment placeAutocompleteFragment = (SupportPlaceAutocompleteFragment) getActivity().getSupportFragmentManager().
findFragmentById(R.id.place_autocomplete_fragment);
placeAutocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
System.out.println(place.getAddress());
}
@Override
public void onError(Status status) {
}
});
Error is on this line in onCreateDialog
method, where layout is inflating:
View view = inflater.inflate(R.layout.add_geofence_layout, null);
XML:
<fragment
android:id="@+id/place_autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.gms.location.places.ui.SupportPlaceAutocompleteFragment" />
Wondering! Why this code works only once?
DialogFragment class:
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.add_geofence_layout, null);
viewHolder = new ViewHolder();
viewHolder.initializeView(view);
viewHolder.placeAutocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
System.out.println(place.getAddress());
}
@Override
public void onError(Status status) {
}
});
}
Note:- I am using a PlaceautoCompleteFragment
inside a DialogFragment
. If i use this inside an Activity it works fine.