0

I am using the Google Map's Places API's AutoCompleteSearchFragment in a Dialog. The error that I am getting occurs when I launch the dialog, close it, then relaunch it.

Error Message:

Error inflating class fragment. Caused by: java.lang.IllegalArgumentException: Binary XML file line #69: Duplicate id 0x7f0a0027, tag null, or parent id 0x7f0a00c7 with another fragment for `com.google.android.libraries.places.widget.AutocompleteSearchFragmet

My code:

Dialog alert = new Dialog(MainActivity.this);
alert.requestWindowFeature(Window.FEATURE_NO_TITLE);
alert.setContentView(R.layout.forgot_info);
alert.setCancelable(true);
alert.getWindow().setBackgroundDrawableResource(android.R.color.transparent);

AutocompleteSupportFragment autocompleteSupportFragment =
   (AutocompleteSupportFragment) getSupportFragmentManager().findFragmentById(R.id.auto2);

The error also goes on to mention android.support.v4.app.FragmentActivity.onCreateView and android.view.LayoutInflater.createViewFromTag.

Is it possible that the duplicate id error is occurring because the Activity believes that there is more than one AutocompleteSearchFragments?

If so, how would I be able to delete or remove the AutocompleteSearchFragment once the Dialog is closed?

Ishaan Javali
  • 1,711
  • 3
  • 13
  • 23
  • https://stackoverflow.com/questions/14083950/duplicate-id-tag-null-or-parent-id-with-another-fragment-for-com-google-androi – Bek Jul 13 '19 at 03:21
  • Thank you for the link @Bek, but I'd already tried those answers and they hadn't worked for me. I think it's because the `AutocompleteSearchFragment` is a little different. – Ishaan Javali Jul 13 '19 at 03:23

1 Answers1

0

I found the solution to the problem, for those that it may help later on.

In order to prevent the Activity from thinking that there is more than one AutocompleteSearchFragment with the same ID each time I open the Dialog, I set a onDismissListener for the Dialog in order to remove the AutocompleteSearchFragment:

The code:

alert.setOnDismissListener(new DialogInterface.OnDismissListener() {
    @Override
    public void onDismiss(DialogInterface dialog) {
        getSupportFragmentManager().beginTransaction().
               remove((Fragment) autocompleteSupportFragment).commit();
    }
});

What the code above does is when the Dialog called alert is dismissed, it uses the SupportFragmentManager to remove that AutocompleteSearchFragment.

Ishaan Javali
  • 1,711
  • 3
  • 13
  • 23