Android Google Places API - PlaceAutocompleteFragment clear button listener

前端 未结 3 803
甜味超标
甜味超标 2021-02-08 23:25

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 la

3条回答
  •  一生所求
    2021-02-08 23:31

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

提交回复
热议问题