在谷歌位置提供的android PlaceAutocompleteFragment搜索小工具中,结果一个接一个



我使用Google Places Api提供的PlaceAutocompleteFragment在我的Android应用程序中集成了自动完成搜索。它工作得很好,但问题是有时自动完成列表中的结果会一个接一个地出现。我无法思考这个问题。我正在添加相同的屏幕截图和代码。

问题的屏幕截图

代码-

布局代码-

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/coord"
    android:fitsSystemWindows="true"
    tools:context="com.restaurantfinder.lazylad91.restaurantfinder.HomeActivity">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay">
            <fragment
                android:id="@+id/place_autocomplete_fragment"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
                />
        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>
    <include layout="@layout/content_home"/>
<!--    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email"/>-->
</android.support.design.widget.CoordinatorLayout>

活动代码-

    AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
            .setTypeFilter(AutocompleteFilter.TYPE_FILTER_ESTABLISHMENT)
            .build();
    autocompleteFragment.setFilter(typeFilter);
    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            // TODO: Get info about the selected place.
            mPlaceSelected = place;
            }
            Log.d("TAG", "Place: " + place.getName());//get place details here
        }

更新

这个错误是由谷歌在问题中处理的

https://issuetracker.google.com/issues/35829225

该修复程序在Google Play Services 9.6(2016年9月21日)中实现

这是Android的自动完成小部件中的一个已知问题。它将在即将发布的版本中修复。

最新更新