【发布时间】:2017-05-11 18:55:42
【问题描述】:
我在Fragment 中使用PlaceAutoCompleteFragment。第一次打开片段(其中放置PlaceAutoCompleteFragment 的应用程序片段)时,它像魅力一样工作得很好。
但是,然后我第二次点击按钮打开 Fragment 它崩溃并出现以下错误。它只工作一次。
致命例外:
android.view.InflateException:二进制 XML 文件第 64 行:错误 膨胀类片段原因: java.lang.IllegalArgumentException:二进制 XML 文件第 64 行: 重复 id 0x7f0d0094、标签 null 或父 id 0xffffffff 另一个片段 com.google.android.gms.location.places.ui.PlaceAutocompleteFragment
这就是我使用它的方式,用于搜索位置
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.parkingview_fragment, container, false);
mapFragment = (SupportMapFragment) this.getChildFragmentManager().findFragmentById(R.id.map_parkingview);
mapFragment.getMapAsync(this);
// For Search location
PlaceAutocompleteFragment autocompleteFragment = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
autocompleteFragment = (PlaceAutocompleteFragment) getActivity().getFragmentManager().findFragmentById(R.id.place_fragment_parkingview);
}
autocompleteFragment.setOnPlaceSelectedListener(this);
autocompleteFragment.setHint("Search a Location");
// autocompleteFragment.setBoundsBias(BOUNDS_MOUNTAIN_VIEW);
return view;
}
XML:
<fragment
android:id="@+id/place_fragment_parkingview"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
【问题讨论】:
-
乔丹的回答是正确的。你应该这样选择它。
标签: android android-fragments inflate-exception