AutocompleteSearchFragment in Dialog gives InflateException

前端 未结 1 1237
灰色年华
灰色年华 2021-01-28 04:26

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 i

相关标签:
1条回答
  • 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.

    0 讨论(0)
提交回复
热议问题