Class CarListTemplate

java.lang.Object
com.codename1.car.CarTemplate
com.codename1.car.CarListTemplate

public class CarListTemplate extends CarTemplate

A scrolling list of selectable rows, optionally grouped into CarSections, with an optional header CarActionStrip. The most common in-car template -- audio browse, POI lists, settings. Maps to androidx.car.app.model.ListTemplate and CPListTemplate.

Head units enforce a hard row cap (see com.codename1.car.spi.CarBridge#getListRowLimit() / CarContext#getListRowLimit()); rows beyond the cap are dropped by the platform.

CarListTemplate t = new CarListTemplate().setTitle("Library");
t.addRow(new CarRow("Songs").setBrowsable(true).setOnAction(ctx -> ctx.pushScreen(new SongsScreen())));
t.addRow(new CarRow("Albums").setBrowsable(true).setOnAction(ctx -> ctx.pushScreen(new AlbumsScreen())));
  • Constructor Details

    • CarListTemplate

      public CarListTemplate()
  • Method Details

    • setTitle

      public CarListTemplate setTitle(String title)

      Sets the header title.

      Parameters
      • title: the header title
      Returns

      this template, for chaining

    • addRow

      public CarListTemplate addRow(CarRow row)

      Adds a row to the template's default (untitled) section, creating it on first use. Use addSection(CarSection) when you need grouped rows.

      Parameters
      • row: the row to add
      Returns

      this template, for chaining

    • addSection

      public CarListTemplate addSection(CarSection section)

      Adds a titled section of rows.

      Parameters
      • section: the section to add
      Returns

      this template, for chaining

    • getSections

      public List<CarSection> getSections()
      Returns the sections of this list, in order.
    • getHeaderActions

      public CarActionStrip getHeaderActions()
      Returns the header action strip, or null.
    • setHeaderActions

      public CarListTemplate setHeaderActions(CarActionStrip headerActions)

      Sets the header action strip (e.g. a refresh or search action).

      Parameters
      • headerActions: the action strip
      Returns

      this template, for chaining

    • isLoading

      public boolean isLoading()
      Returns true when the list should render a loading spinner instead of content.
    • setLoading

      public CarListTemplate setLoading(boolean loading)

      Marks the template as loading; the head unit renders a spinner and ignores any rows. Set this while fetching content, then CarScreen#invalidate() once the rows are ready.

      Parameters
      • loading: true to show a spinner
      Returns

      this template, for chaining