Ad

How To Set Filter For AutocompleteSupportFragment Api Updated After Jan 2019

- 1 answer

how to set filter for country for AutocompleteSupportFragment autocomplete edittext place api with

AutocompleteFilter typeFilter = new AutocompleteFilter.Builder().setCountry("IN").build();

not working with new release of google api for place location for AutocompleteSupportFragment.

xml file

fragment
            android:id="@+id/autocomplete_fragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment"

java file

AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment)
                getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
Ad

Answer

use this:

autocompleteFragment.setCountry("IN"); 

textView without intent it is also useful:

autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
   @Override public void onPlaceSelected(Place place) { 
   txtVw.setText(place.getName()+" >> "+place.getLatLng()); 
 } 
@Override public void onError(Status status) {
   txtVw.setText(status.toString()); 
  } 
 }
);
Ad
source: stackoverflow.com
Ad