public final class

SearchTemplate.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.car.app.model.SearchTemplate.Builder

Overview

A builder of SearchTemplate.

Summary

Constructors
publicBuilder(SearchTemplate.SearchCallback callback)

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

Methods
public SearchTemplatebuild()

Constructs the SearchTemplate model.

public SearchTemplate.BuildersetActionStrip(ActionStrip actionStrip)

Sets the ActionStrip for this template.

public SearchTemplate.BuildersetHeaderAction(Action headerAction)

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

public SearchTemplate.BuildersetInitialSearchText(java.lang.String initialSearchText)

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

public SearchTemplate.BuildersetItemList(ItemList itemList)

Sets the ItemList to show for search results.

public SearchTemplate.BuildersetLoading(boolean isLoading)

Sets whether the template is in a loading state.

public SearchTemplate.BuildersetSearchHint(java.lang.String searchHint)

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

public SearchTemplate.BuildersetShowKeyboardByDefault(boolean showKeyboardByDefault)

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

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

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 .

Parameters:

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

Methods

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.

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(CharSequence). Otherwise, only Actions with icons are allowed.

public SearchTemplate.Builder setInitialSearchText(java.lang.String initialSearchText)

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

public SearchTemplate.Builder setSearchHint(java.lang.String searchHint)

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

The host will use a default search hint if not set with this method.

This is not the actual search text, and will disappear if user types any value into the search.

If a non empty text is set via SearchTemplate.Builder.setInitialSearchText(String), the searchHint will not show, unless the user erases the search text.

public SearchTemplate.Builder setLoading(boolean isLoading)

Sets whether the template is in a loading state.

If set to true, the UI will display a loading indicator where the list content would be otherwise. The caller is expected to call Screen.invalidate() and send the new template content to the host once the data is ready. If set to false, the UI shows the ItemList contents added via SearchTemplate.Builder.setItemList(ItemList).

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 via ItemList.Builder.setOnSelectedListener(ItemList.OnSelectedListener). Each Row can add up to 2 lines of texts via Row.Builder.addText(CharSequence) and cannot contain a Toggle.

See also: ConstraintManager.getContentLimit(int)

public SearchTemplate.Builder setShowKeyboardByDefault(boolean showKeyboardByDefault)

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

Defaults to true.

public SearchTemplate build()

Constructs the SearchTemplate model.