【问题标题】:Multiple PlaceAutoCompleteFragment opens when clicked on it very quickly快速单击多个 PlaceAutoCompleteFragment 时会打开它
【发布时间】:2016-05-29 12:21:48
【问题描述】:

我在最近的一个项目中使用了 Google 的 PlaceAutoCompleteFragment。当我很快点击 PlaceAutoCompleteFragment 时,它会在我的应用程序上打开多个叠加层,这真的很烦人。如何防止它打开多个叠加层?我的片段代码如下:

if (autocompleteFragment == null) {
        autocompleteFragment = (PlaceAutocompleteFragment)getFragmentManager().findFragmentById(R.id.place_autocompletehome_fragment);
}

autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            // TODO: Get info about the selected place.
            try {
                Log.i("esty", "Place: " + place.getName());



            } catch (Exception e) {
                Log.e("esty", "Error: " + e.getMessage());
            }

        }

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

【问题讨论】:

    标签: android android-fragments google-places-api


    【解决方案1】:

    看起来这是PlaceAutocompleteFragment(和SupportPlaceAutocompleteFragment)中的一个错误。感谢您提请我们注意。我们将在即将发布的版本中解决此问题。

    【讨论】:

    • 该死的现在我必须使用 PlaceAutoComplete 意图构建器。感谢您的回复。
    • 意图构建器 PlaceAutocomplete.MODE_OVERLAY 存在相同问题。
    【解决方案2】:

    你为什么不尝试破解来解决这个问题。 在整个片段上放置一个点击监听器,并使用多次点击拦截器将点击事件传递一次。

    参考以下解决方案: https://stackoverflow.com/a/23103227/4901098

    【讨论】:

    • PlaceAutoCompleteFragment 没有 onclicklistener。但你的解决方案可能给了我一个想法。将使用 PlaceAutoComplete Intent Builder 来实现此解决方案。
    猜你喜欢
    • 2015-10-30
    • 1970-01-01
    • 2012-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多