【问题标题】:PlaceAutocompleteFragment disappears on clickPlaceAutocompleteFragment 在点击时消失
【发布时间】:2017-04-13 12:53:01
【问题描述】:

我想实现 AutocompleteTextView(google 地方),但是当我单击片段中的 searchView 时,片段消失(掉下来)。

我的代码:

 @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>

感谢您的建议

【问题讨论】:

    标签: android google-maps google-maps-android-api-2 autocompletetextview


    【解决方案1】:

    我遇到了同样的问题。我把 API 控制台搞砸了 https://console.developers.google.com/ 启用 Maps API AND Android 的 Places API,现在它工作正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-25
      • 2014-11-20
      • 1970-01-01
      相关资源
      最近更新 更多