android – 将PlaceAutocompleteFragment添加到片段抛出错误
作者:互联网
我已在活动中实施了PlaceAutocompleteFragment,并且正在成功运作.但是如何在android中的片段中实现相同的?
我已经实现了像这样的placeautocomplete片段
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,android-fragments,google-places-api 来源: https://codeday.me/bug/20191005/1856445.html