我試圖使用Google的Place自動填充(https://developers.google.com/places/android-api/autocomplete)在我的應用中實現片段。但是我從這個片段到另一個片段中導航,然後回來這個片段如何將Google的PlaceAutoCompleteFragment實現爲擴展片段的類
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)中的答案,但我找不到任何解決方案此地方Aut ocomplete片段
給你自己的'PlaceAutoComplete'一個id。 – tahsinRupam
@tahsinRupam你是什麼意思?任何例子? –
可能這是因爲你在兩個不同的'PlaceAutoComplete'片段中使用了相同的id。 – tahsinRupam