SearchTemplate.Builder

public static final class SearchTemplate.Builder
extends Object

java.lang.Object
   ↳ androidx.car.app.model.SearchTemplate.Builder


A builder of SearchTemplate.

Summary

Public constructors

Builder(SearchTemplate.SearchCallback callback)

Returns a new instance of a SearchTemplate.Builder with the input SearchTemplate.SearchCallback.

Public methods

SearchTemplate build()

Constructs the SearchTemplate model.

SearchTemplate.Builder setActionStrip(ActionStrip actionStrip)

Sets the ActionStrip for this template.

SearchTemplate.Builder setHeaderAction(Action headerAction)

Sets the Action that will be displayed in the header of the template.

SearchTemplate.Builder setInitialSearchText(String initialSearchText)

Sets the initial search text to display in the search box.

SearchTemplate.Builder setItemList(ItemList itemList)

Sets the ItemList to show for search results.

SearchTemplate.Builder setLoading(boolean isLoading)

Sets whether the template is in a loading state.

SearchTemplate.Builder setSearchHint(String searchHint)

Sets the text hint to display in the search box when it is empty.

SearchTemplate.Builder setShowKeyboardByDefault(boolean showKeyboardByDefault)

Sets if the keyboard should be displayed by default, instead of waiting until user interacts with the search box.

Inherited methods

Public constructors

Builder

public Builder (SearchTemplate.SearchCallback callback)

Returns a new instance of a SearchTemplate.Builder with the input SearchTemplate.SearchCallback.

Note that the callback relates to UI events and will be executed on the main thread using Looper.getMainLooper().

Parameters
callback SearchTemplate.SearchCallback: the callback to be invoked for events such as when the user types new text, or submits a search

Public methods

build

public SearchTemplate build ()

Constructs the SearchTemplate model.

Returns
SearchTemplate

Throws
IllegalArgumentException if the template is in a loading state but the list is set

setActionStrip

public SearchTemplate.Builder setActionStrip (ActionStrip actionStrip)

Sets the ActionStrip for this template.

Unless set with this method, the template will not have an action strip.

Requirements

This template allows up to 2 Actions in its ActionStrip. Of the 2 allowed Actions, one of them can contain a title as set via Action.Builder.setTitle(CarText). Otherwise, only Actions with icons are allowed.

Parameters
actionStrip ActionStrip

Returns
SearchTemplate.Builder

Throws
IllegalArgumentException if actionStrip does not meet the requirements
NullPointerException if actionStrip is null

setHeaderAction

public SearchTemplate.Builder setHeaderAction (Action headerAction)

Sets the Action that will be displayed in the header of the template.

Unless set with this method, the template will not have a header action.

Requirements

This template only supports either one of Action.APP_ICON and Action.BACK as a header Action.

Parameters
headerAction Action

Returns
SearchTemplate.Builder

Throws
IllegalArgumentException if headerAction does not meet the template's requirements
NullPointerException if headerAction is null

setInitialSearchText

public SearchTemplate.Builder setInitialSearchText (String initialSearchText)

Sets the initial search text to display in the search box.

Parameters
initialSearchText String

Returns
SearchTemplate.Builder

Throws
NullPointerException if initialSearchText is null

setItemList

public SearchTemplate.Builder setItemList (ItemList itemList)

Sets the ItemList to show for search results.

The list will be shown below the search box, allowing users to click on individual search results.

Requirements

The number of items in the ItemList should be smaller or equal than the limit provided by ConstraintManager.CONTENT_LIMIT_TYPE_LIST. The host will ignore any items over that limit. The list itself cannot be selectable as set v