public final class

Row.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.car.app.model.Row.Builder

Overview

A builder of Row.

Summary

Constructors
publicBuilder()

Returns an empty Row.Builder instance.

Methods
public Row.BuilderaddText(CarText text)

Adds a text string to the row below the title, with support for multiple length variants.

public Row.BuilderaddText(java.lang.CharSequence text)

Adds a text string to the row below the title.

public Rowbuild()

Constructs the Row defined by this builder.

public Row.BuildersetBrowsable(boolean isBrowsable)

Shows an icon at the end of the row that indicates that the row is browsable.

public Row.BuildersetImage(CarIcon image)

Sets an image to show in the row with the default size Row.IMAGE_TYPE_SMALL.

public Row.BuildersetImage(CarIcon image, int imageType)

Sets an image to show in the row with the given image type.

public Row.BuildersetMetadata(Metadata metadata)

Sets the Metadata associated with the row.

public Row.BuildersetOnClickListener(OnClickListener onClickListener)

Sets the OnClickListener to be called back when the row is clicked.

public Row.BuildersetTitle(CarText title)

Sets the title of the row, with support for multiple length variants.

public Row.BuildersetTitle(java.lang.CharSequence title)

Sets the title of the row.

public Row.BuildersetToggle(Toggle toggle)

Sets a Toggle to show in the row.

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

Constructors

public Builder()

Returns an empty Row.Builder instance.

Methods

public Row.Builder setTitle(java.lang.CharSequence title)

Sets the title of the row.

Only DistanceSpans and DurationSpans are supported in the input string.

public Row.Builder setTitle(CarText title)

Sets the title of the row, with support for multiple length variants.

Only DistanceSpans and DurationSpans are supported in the input string.

public Row.Builder addText(java.lang.CharSequence text)

Adds a text string to the row below the title.

The text can be customized with ForegroundCarColorSpan, DistanceSpan, and DurationSpan instances, any other spans will be ignored by the host.

Most templates allow up to 2 text strings, but this may vary. This limit is documented in each individual template.

Text Wrapping

Each string added with this method will not wrap more than 1 line in the UI, with one exception: if the template allows a maximum number of text strings larger than 1, and the app adds a single text string, then this string will wrap up to the maximum.

For example, assuming 2 lines are allowed in the template where the row will be used, this code:

 rowBuilder
     .addText("This is a rather long line of text")
     .addText("More text")
 

would wrap the text like this:

 This is a rather long li...
 More text
 
In contrast, this code:
 rowBuilder
     .addText("This is a rather long line of text. More text")
 

would wrap the single line of text at a maximum of 2 lines, producing a different result:

 This is a rather long line
 of text. More text
 

Note that when using a single line, a line break character can be used to break it into two, but the results may be unpredictable depending on the width the text is wrapped at:

 rowBuilder
     .addText("This is a rather long line of text\nMore text")
 

would produce a result that may loose the "More text" string:

 This is a rather long line
 of text
 

See also: ForegroundCarColorSpan

public Row.Builder addText(CarText text)

Adds a text string to the row below the title, with support for multiple length variants.

See also: Row.Builder.addText(CharSequence)

public Row.Builder setImage(CarIcon image)

Sets an image to show in the row with the default size Row.IMAGE_TYPE_SMALL.

See also: Row.Builder.setImage(CarIcon, int)

public Row.Builder setImage(CarIcon image, int imageType)

Sets an image to show in the row with the given image type.

For a custom CarIcon, its IconCompat instance can be of IconCompat.TYPE_BITMAP, IconCompat.TYPE_RESOURCE, or IconCompat.TYPE_URI.

Image Sizing Guidance

If the input image's size exceeds the sizing requirements for the given image type in either one of the dimensions, it will be scaled down to be centered inside the bounding box while preserving its aspect ratio.

See CarIcon for more details related to providing icon and image resources that work with different car screen pixel densities.

Parameters:

image: the CarIcon to display or null to not display one
imageType: one of Row.IMAGE_TYPE_ICON, Row.IMAGE_TYPE_SMALL or Row.IMAGE_TYPE_LARGE

public Row.Builder setToggle(Toggle toggle)

Sets a Toggle to show in the row.

public Row.Builder setBrowsable(boolean isBrowsable)

Shows an icon at the end of the row that indicates that the row is browsable.

Browsable rows can be used, for example, to represent the parent row in a hierarchy of lists with child lists.

If a row is browsable, then no Action or Toggle can be added to it.

public Row.Builder setOnClickListener(OnClickListener onClickListener)

Sets the OnClickListener to be called back when the row is clicked.

Note that the listener relates to UI events and will be executed on the main thread using .

public Row.Builder setMetadata(Metadata metadata)

Sets the Metadata associated with the row.

Parameters:

metadata: The metadata to set with the row. Pass Metadata.EMPTY_METADATA to not associate any metadata with the row

public Row build()

Constructs the Row defined by this builder.