我已經使用Google Places Api提供的PlaceAutocompleteFragment來將自動填充搜索集成到我的Android應用程序中。 它工作正常,但問題是某些時候自動完成列表中的結果正在接近另一個。 我無法思考這個問題。我添加了相同的屏幕截圖和代碼。結果在android中PlaceAutocompleteFragment搜索小工具一個接一個地提供
碼 -
佈局代碼 -
<?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://code.google.com/p/gmaps-api-issues/issues/detail?id=10292 – Stuartsoft
現已在Google Play Services 9.6中爲Jellybean及更高版本修復此問題。 –