自动完成支持片段问题:在键入期间关闭搜索栏

Autocomplete Support Fragment issue : closes search bar during typing

我一直在尝试通过以下步骤使用新的 Places SDK 应用 Android Google Places Autocomplete 功能:

添加依赖项

implementation 'com.google.android.libraries.places:places:2.2.0'
implementation 'androidx.cardview:cardview:1.0.0'

已添加权限

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

在xml 文件

<androidx.cardview.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:layout_marginTop="5dp"
    app:cardCornerRadius="4dp">
    <fragment
        android:id="@+id/autocomplete_fragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"                                 
     android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment"/>

</androidx.cardview.widget.CardView>

在我的 Activity 文件中

// Initialize Places.
Places.initialize(getApplicationContext(), "My API KEY");

// Create a new Places client instance.
PlacesClient placesClient = Places.createClient(this);

// Initialize the AutocompleteSupportFragment.
AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment) getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);

// Specify the types of place data to return.
autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));

// Set up a PlaceSelectionListener to handle the response.
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
    @Override
    public void onPlaceSelected(Place place) {
        // TODO: Get info about the selected place.
        //Log.i(TAG, "Place: " + place.getName() + ", " + place.getId());
    }

    @Override
    public void onError(Status status) {
        // TODO: Handle the error.
        //Log.i(TAG, "An error occurred: " + status);
    }
});

问题是当我尝试在搜索栏上键入任意键时它关闭了搜索 window。

注意:API 键已启用,在启用 API 键后,我得到了相同的 API,我已经在这个项目中为 'Maps SDK for Android' 启用了。

如果有人得到解决方案请提供。

提前致谢。

这个地方选择器方法在 2019 年已经被弃用。请按照最新的方法来实现这里的地方选择器是 link https://developers.google.com/places/android-sdk/client-migration