gpt4 book ai didi

android - 将 PlaceAutocompleteFragment 添加到 fragment 会引发错误

转载 作者:IT王子 更新时间:2023-10-28 23:33:28 26 4
gpt4 key购买 nike

我已经在 Activity 中实现了 PlaceAutocompleteFragment 并且工作成功。但是如何在android的 fragment 中实现相同的功能?我已经实现了这样的 placeautocomplete fragment

 PlaceAutocompleteFragment autocompleteFragment1 = (PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment1);

我得到的错误是

Incovertible types;cannot cast 'android.support.v4.app.Fragment' to com.google.android.gms.location.PlaceAutocompleteFragment '.

XML 布局是

  <android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_background"
card_view:cardCornerRadius="4dp"
card_view:contentPadding="0dp">
<fragment
android:id="@+id/place_autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Place"
android:background="#fff"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
/>
</android.support.v7.widget.CardView>

提前致谢

最佳答案

像这样使用getActivity()

PlaceAutocompleteFragment autocompleteFragment1  = (PlaceAutocompleteFragment)getActivity().getFragmentManager().findFragmentById(R.id.autocomplete_fragment1);

关于android - 将 PlaceAutocompleteFragment 添加到 fragment 会引发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36996672/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com