【发布时间】:2017-05-29 04:23:21
【问题描述】:
我正在尝试使用 Google 的 Place Autocomplete (https://developers.google.com/places/android-api/autocomplete) 在我的应用中实现片段。但是当我从这个片段导航到另一个片段然后回到这个片段时,我得到了这个错误
Caused by: java.lang.IllegalArgumentException: Binary XML file line #30: Duplicate id 0x7f0f010f, tag null, or parent id 0x7f0f00c0 with another fragment for com.google.android.gms.location.places.ui.PlaceAutocompleteFragment
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2148)
这是java代码
private PlaceAutocompleteFragment mSearchPAF;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.some_layout, container, false);
mSearchLocationPAF = (PlaceAutocompleteFragment) parentActivity.getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
}
这是 XML 文件
<RelativeLayout
android:id="@+id/someRelativeLayout"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="30dp"
android:background="@drawable/some_drawable">
<fragment
android:id="@+id/place_autocomplete_fragment"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
我在同一个 java 和 xml 文件中还有另一个地图片段,但我设法按照这篇文章 (Duplicate ID, tag null, or parent id with another fragment for com.google.android.gms.maps.MapFragment) 中的答案解决了这个问题,但我找不到这个地方自动完成片段的任何解决方案
【问题讨论】:
-
给你自己的
PlaceAutoComplete一个id。 -
@tahsinRupam 你这是什么意思?有什么例子吗?
-
可能这会导致您在两个不同的
PlaceAutoComplete片段中使用相同的 ID。 -
你在 PlaceAutocomplete 的两个片段中使用相同的 id
-
@Sandeepdhiman 如果你的意思是这个 (android:id="@+id/place_autocomplete_fragment") 那么没有
标签: java android android-fragments google-places-api