Android Google Places API - PlaceAutocompleteFragment 清除按钮侦听器

2024-03-11

I am using Google Places API for Android - PlaceAutocompleteFragment https://developers.google.com/places/android-api/ API in my project to search locations, when user selects a location then get the records using location lat-long and display it to ListView.

Now the problem is whenever user taps on clear button (X) of PlaceAutocompleteFragment https://developers.google.com/android/reference/com/google/android/gms/location/places/ui/PlaceAutocompleteFragment I want clear ListView items for which I need to listen to clear button onClick? How to do that?

enter image description here
Any help will be appreciated.

autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
    @Override
    public void onPlaceSelected(Place place) {
        LatLng latLng=place.getLatLng();
        //hit web service, response parsing and add it to listview.
    }

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

查看源代码PlaceAutocompleteFragment我找到了这些视图 ID 并设置了onClickListener像这样:

autocompleteFragment.getView().findViewById(R.id.place_autocomplete_clear_button)
    .setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // example : way to access view from PlaceAutoCompleteFragment
            // ((EditText) autocompleteFragment.getView()
            // .findViewById(R.id.place_autocomplete_search_input)).setText(""); 
            autocompleteFragment.setText("");
            view.setVisibility(View.GONE);
        }
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android Google Places API - PlaceAutocompleteFragment 清除按钮侦听器 的相关文章

随机推荐