PlaceAutocompleteFragment 在点击时消失 [英] PlaceAutocompleteFragment disappears on click
本文介绍了PlaceAutocompleteFragment 在点击时消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想实现 AutocompleteTextView(谷歌位置),但是当我点击片段中的 searchView 时,片段消失(倒下).
I wanted to implement AutocompleteTextView (google places) but when I click to searchView in a fragment, the fragment disappears (fell down).
我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_autocomplete);
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
.setTypeFilter(AutocompleteFilter.TYPE_FILTER_CITIES)
.build();
autocompleteFragment.setFilter(typeFilter);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(com.google.android.gms.location.places.Place place) {
// TODO: handle click
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
}
});
}
xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="ui.screen.activity.AutocompleteActivity">
<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>
感谢您的建议
推荐答案
我遇到了同样的问题.我搞砸了 API 控制台https://console.developers.google.com/ 启用 Maps API ANDstrong> 适用于 Android 的 Places API,现在工作正常.
I had the same problem. I messed up a little bit with the API Console https://console.developers.google.com/ enabling the Maps API AND the Places API for Android and now it's working fine.
这篇关于PlaceAutocompleteFragment 在点击时消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文