我正在尝试将一个 fragment 插入另一个 fragment ,并且我已经成功地做到了这一点,直到我第一次吃完主 fragment ,它才开始工作,但是当我试图重新加载 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
这是我的 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
}
这是我的 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>
最佳答案
我刚遇到同样的问题,可以通过删除 onDismiss 回调中的 fragment 来解决。
@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();
}
}
关于android - 二进制 XML 文件第 26 行 : Duplicate id, 标记为空,或带有另一个 fragment 的父 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37959617/