AutocompleteSupportFragment

public class AutocompleteSupportFragment extends Fragment


Implements a fragment that presents a search box button to the user, which presents a search box UI when clicked. As the user types, the autocomplete service returns Place predictions for places such as businesses, addresses and points of interest. When the user selects a place, the autocomplete service returns the response via the PlaceSelectionListener.

Summary

Public constructors

Public methods

static AutocompleteSupportFragment

Create a new autocomplete fragment with default config.

void
onActivityResult(int requestCode, int resultCode, @Nullable Intent data)

This method is deprecated.

void
onCreate(@Nullable Bundle savedInstanceState)
void
void
void
onViewCreated(View view, @Nullable Bundle savedInstanceState)
AutocompleteSupportFragment

Sets the type of activity to open when a user initiates a query.

AutocompleteSupportFragment
setCountries(String[] countries)

See setCountries.

AutocompleteSupportFragment
setCountries(List<String> countries)

Sets countries to restrict results to.

AutocompleteSupportFragment

This method is deprecated.

Use setCountries instead.

AutocompleteSupportFragment

Sets the hint text to display in the search input field when there is no text entered.

AutocompleteSupportFragment

Biases the autocomplete results to a particular area.

AutocompleteSupportFragment
setLocationRestriction(
    @Nullable LocationRestriction locationRestriction
)

Restricts the autocomplete results to a particular area.

AutocompleteSupportFragment

Sets a listener that will be notified when a place is selected.

AutocompleteSupportFragment

Sets the desired fields of the Place object returned from selecting an autocomplete result.

AutocompleteSupportFragment

Sets the unicode country/region code (CLDR) of the location where the request is coming from.

AutocompleteSupportFragment

Sets the text to display in the search input field.

AutocompleteSupportFragment

This method is deprecated.

Use setTypesFilter.

AutocompleteSupportFragment
setTypesFilter(List<String> placeTypes)

Sets the filter that restricts the type(s) of results returned from the response.

Extension functions

final @NonNull Flow<@NonNull PlaceSelectionResult>

Returns a Flow of PlaceSelectionResults that are emitted when a place is selected or an error occurs.

Inherited methods

From androidx.fragment.app.Fragment
void
dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)
final boolean
final FragmentActivity
boolean
boolean
final Bundle
final FragmentManager
Context
CreationExtras
ViewModelProvider.Factory
Object
Object
final FragmentManager

This method is deprecated.

final Object
final int
final LayoutInflater
Lifecycle
LoaderManager

This method is deprecated.

final Fragment
final FragmentManager
Object
final Resources
final boolean

This method is deprecated.

Object
final SavedStateRegistry
Object
Object
final String
getString(int resId)
final String
final Fragment

This method is deprecated.

final int

This method is deprecated.

final CharSequence
getText(int resId)
boolean

This method is deprecated.

View
LifecycleOwner
LiveData<LifecycleOwner>
ViewModelStore
final boolean
final int
static Fragment
instantiate(Context context, String fname)

This method is deprecated.

final boolean
final boolean
final boolean
final boolean
final boolean
final boolean
final boolean
final boolean
final boolean
void
onActivityCreated(Bundle savedInstanceState)

This method is deprecated.

void
onAttach(Context context)
void
onAttachFragment(Fragment childFragment)

This method is deprecated.

void
boolean
Animation
onCreateAnimation(int transit, boolean enter, int nextAnim)
Animator
onCreateAnimator(int transit, boolean enter, int nextAnim)
void
onCreateContextMenu(
    ContextMenu menu,
    View v,
    ContextMenu.ContextMenuInfo menuInfo
)
void

This method is deprecated.

View
onCreateView(
    LayoutInflater inflater,
    ViewGroup container,
    Bundle savedInstanceState
)
void
void

This method is deprecated.

void
void
LayoutInflater
onGetLayoutInflater(Bundle savedInstanceState)
void
onHiddenChanged(boolean hidden)
void
onInflate(
    Context context,
    AttributeSet attrs,
    Bundle savedInstanceState
)
void

This method is deprecated.

void
onMultiWindowModeChanged(boolean isInMultiWindowMode)
boolean

This method is deprecated.

void

This method is deprecated.

void
void
onPictureInPictureModeChanged(boolean isInPictureInPictureMode)
void

This method is deprecated.

void
onPrimaryNavigationFragmentChanged(
    boolean isPrimaryNavigationFragment
)
void
onRequestPermissionsResult(
    int requestCode,
    String[] permissions,
    int[] grantResults
)

This method is deprecated.

void
void
void
onViewStateRestored(Bundle savedInstanceState)
void
final ActivityResultLauncher<I>
<I, O> registerForActivityResult(
    ActivityResultContract<I, O> contract,
    ActivityResultCallback<O> callback
)
void
final void
requestPermissions(String[] permissions, int requestCode)

This method is deprecated.

final FragmentActivity
final Bundle
final Context
final FragmentManager

This method is deprecated.

final Object
final Fragment
final View
void
void
void
void
void
void
void
void
setHasOptionsMenu(boolean hasMenu)

This method is deprecated.

void
void
setMenuVisibility(boolean menuVisible)
void
void
setRetainInstance(boolean retain)

This method is deprecated.

void
void
void
void
setTargetFragment(Fragment fragment, int requestCode)

This method is deprecated.

void
setUserVisibleHint(boolean isVisibleToUser)

This method is deprecated.

boolean
void
void
startActivityForResult(Intent intent, int requestCode)

This method is deprecated.

void
startIntentSenderForResult(
    IntentSender intent,
    int requestCode,
    Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags,
    Bundle options
)

This method is deprecated.

void
String
void

Public constructors

AutocompleteSupportFragment

public AutocompleteSupportFragment()

Public methods

newInstance

public static AutocompleteSupportFragment newInstance()

Create a new autocomplete fragment with default config.

onActivityResult

public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)

onCreate

public void onCreate(@Nullable Bundle savedInstanceState)

onResume

public void onResume()

onSaveInstanceState

public void onSaveInstanceState(Bundle bundle)

onViewCreated

public void onViewCreated(View view, @Nullable Bundle savedInstanceState)

setActivityMode

public AutocompleteSupportFragment setActivityMode(AutocompleteActivityMode mode)

Sets the type of activity to open when a user initiates a query.

setCountries

public AutocompleteSupportFragment setCountries(String[] countries)

See setCountries.

setCountries

public AutocompleteSupportFragment setCountries(List<String> countries)

Sets countries to restrict results to.

This must be a list of ISO 3166-1 Alpha-2 country codes (case insensitive). If no countries are set, no country filtering will take place.

This will override values set with setCountry.

Up to five countries are supported. See the components parameter here.

setCountry

public AutocompleteSupportFragment setCountry(@Nullable String country)

See setCountries for details.

This will override countries set with setCountries.

setHint

public AutocompleteSupportFragment setHint(@Nullable CharSequence hint)

Sets the hint text to display in the search input field when there is no text entered.

If the hint is unset or explicitly set to null, the hint text will be set to the default value.

setLocationBias

public AutocompleteSupportFragment setLocationBias(@Nullable LocationBias locationBias)

Biases the autocomplete results to a particular area.

setLocationRestriction

public AutocompleteSupportFragment setLocationRestriction(
    @Nullable LocationRestriction locationRestriction
)

Restricts the autocomplete results to a particular area.

setOnPlaceSelectedListener

public AutocompleteSupportFragment setOnPlaceSelectedListener(@Nullable PlaceSelectionListener listener)

Sets a listener that will be notified when a place is selected.

Parameters
@Nullable PlaceSelectionListener listener

The listener that should be notified.

setPlaceFields

public AutocompleteSupportFragment setPlaceFields(List<Place.Field> placeFields)

Sets the desired fields of the Place object returned from selecting an autocomplete result.

Read more about Place Data Fields.

setRegionCode

public AutocompleteSupportFragment setRegionCode(@Nullable String regionCode)

Sets the unicode country/region code (CLDR) of the location where the request is coming from.

The region code field is only supported by Places API (New). Please enable your API key for the Places API (New) in the Google Cloud Console to use region code. If you do not enable your API key for the Places API (New), the region code will not affect the results.

setText

public AutocompleteSupportFragment setText(@Nullable CharSequence text)

Sets the text to display in the search input field.

setTypeFilter

public AutocompleteSupportFragment setTypeFilter(@Nullable TypeFilter typeFilter)

Restricts the autocomplete results to the given place type.

setTypesFilter

public AutocompleteSupportFragment setTypesFilter(List<String> placeTypes)

Sets the filter that restricts the type(s) of results returned from the response.

Up to 5 place types are supported. A comprehensive list of the supported types can be found in com.google.android.libraries.places.api.model.PlaceTypes. The type collections specified in table 3 must be passed in as solo entries and cannot be combined with any other entries from table 1 or 2.

This will override setTypeFilter if both are used.

Extension functions

AutocompleteSupportFragmentKt.placeSelectionEvents

public final @NonNull Flow<@NonNull PlaceSelectionResultAutocompleteSupportFragmentKt.placeSelectionEvents(
    @NonNull AutocompleteSupportFragment receiver
)

Returns a Flow of PlaceSelectionResults that are emitted when a place is selected or an error occurs.