skadoosh skadoosh - 6 months ago 43
Android Question

Android Google Places API - PlaceAutocompleteFragment clear button listener

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?

enter image description here

Any help will be appreciated.

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

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

Answer Source

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

    .setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            // example : way to access view from PlaceAutoCompleteFragment
            // ((EditText) autocompleteFragment.getView()
            // .findViewById(""); 

Happy_Coding :-)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download