【发布时间】:2017-12-03 17:02:34
【问题描述】:
您好,我在我的应用中使用了谷歌的地点自动完成 API。我需要谷歌将片段放在另一个片段中并让它工作。基本上我有一个带有 3 个图像视图的选项卡,当您单击一个时,一个片段将填充主框架布局。最初,如果我单击显示带有自动完成位置片段的片段的 imagview,它会起作用。但是,如果我转到另一个选项卡然后返回它,我会在 google 位置自动完成片段上收到重复的 id 错误。
这是包含自动完成片段的片段的 xml:
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/dialog_holo_light_frame"
android:orientation="vertical">
<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="42dp"
android:background="@android:drawable/dialog_frame"
tools:layout="@layout/place_autocomplete_fragment" />
这是包含自动完成片段的片段中的代码:
this.locationSearchBar = (PlaceAutocompleteFragment)getActivity().getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
这是我得到的错误:
Duplicate id 0x7f0800dc, tag null, or parent id 0x7f0800f6 with another fragment for com.google.android.gms.location.places.ui.PlaceAutocompleteFragment
我阅读了其他类似的问题,但他们的解决方案都不适合我。任何帮助将不胜感激。
【问题讨论】:
-
您是否尝试过简单地更改片段 ID?或者您使用的每个 id 都会出现错误?因为您有一个使用
tools:layout=@layout/place_autocomplete_fragment引用的同名布局 -
您正在尝试查找 Activity 的片段...不是来自当前片段
-
我每个 id 都得到它
-
@Mat
tools:属性在编译时被移除 -
@cricket_007 第二次放大片段布局时出现错误。就好像自动完成片段永远不会被破坏,即使它所在的片段是。
标签: android android-fragments android-nested-fragment