Android Google Places API-PlaceAutocompleteFragment清除按钮侦听器 [英] Android Google Places API - PlaceAutocompleteFragment clear button listener

查看:80
本文介绍了Android Google Places API-PlaceAutocompleteFragment清除按钮侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用 Android版Google Places API-PlaceAutocompleteFragment API来搜索位置,当用户选择一个位置后,使用经纬度的位置获取记录,并将其显示在ListView中.

现在的问题是,只要用户点击

I am using Google Places API for Android - PlaceAutocompleteFragment 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 I want clear ListView items for which I need to listen to clear button onClick? How to do that?


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像这样:

Looking at the source code of PlaceAutocompleteFragment I found those view ids and setup a onClickListener like this:

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);
        }
});

这篇关于Android Google Places API-PlaceAutocompleteFragment清除按钮侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆