# GridTemplate

Artifact: [androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app) [View Source](https://cs.android.com/search?q=file:androidx/car/app/model/GridTemplate.java+class:androidx.car.app.model.GridTemplate) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

*** ** * ** ***


```
@CarProtocol
public final class GridTemplate implements Template
```

<br />

*** ** * ** ***

A template representing a grid of items.

#### Template Restrictions

In regards to template refreshes, as described in `https://developer.android.com/reference/androidx/car/app/Screen#onGetTemplate()`, this template is considered a refresh of a previous one if:

- The previous template is in a loading state (see `https://developer.android.com/reference/androidx/car/app/model/GridTemplate.Builder#setLoading(boolean)`, or
- The template title has not changed, and the number of grid items and the title of each grid item have not changed.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/car/app/model/GridTemplate.Builder` A builder of `https://developer.android.com/reference/androidx/car/app/model/GridTemplate`. |

| ### Constants |
|---|---|
| `static final int` | `@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 8) https://developer.android.com/reference/androidx/car/app/model/GridTemplate#ITEM_IMAGE_SHAPE_CIRCLE() = 2` Represents a preference to crop all grid item images into the shape of a circle. |
| `static final int` | `@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 8) https://developer.android.com/reference/androidx/car/app/model/GridTemplate#ITEM_IMAGE_SHAPE_UNSET() = 1` Represents a preference to keep the images as-is without modifying their shape. |
| `static final int` | `@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 8) https://developer.android.com/reference/androidx/car/app/model/GridTemplate#ITEM_SIZE_LARGE() = 4` Represents a large size for all grid items within a template. |
| `static final int` | `@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 8) https://developer.android.com/reference/androidx/car/app/model/GridTemplate#ITEM_SIZE_MEDIUM() = 2` Represents a medium size for all grid items within a template. |
| `static final int` | `@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 8) https://developer.android.com/reference/androidx/car/app/model/GridTemplate#ITEM_SIZE_SMALL() = 1` Represents a small size for all grid items within a template. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/car/app/model/GridTemplate#equals(java.lang.Object)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.html other)` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/model/ActionStrip` | `[getActionStrip](https://developer.android.com/reference/androidx/car/app/model/GridTemplate#getActionStrip())()` **This method is deprecated.** use `https://developer.android.com/reference/androidx/car/app/model/Header#getEndHeaderActions()` instead. <br /> |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/car/app/model/Action>` | `@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 7) https://developer.android.com/reference/androidx/car/app/model/GridTemplate#getActions()()` Returns the list of additional actions. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/model/Header` | `https://developer.android.com/reference/androidx/car/app/model/GridTemplate#getHeader()()` Returns the `https://developer.android.com/reference/androidx/car/app/model/Header` to display in this template. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/model/Action` | `[getHeaderAction](https://developer.android.com/reference/androidx/car/app/model/GridTemplate#getHeaderAction())()` **This method is deprecated.** use `https://developer.android.com/reference/androidx/car/app/model/Header#getStartHeaderAction()` instead. <br /> |
| `int` | `@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 8) https://developer.android.com/reference/androidx/car/app/model/GridTemplate#getItemImageShape()()` Returns the item image shape. |
| `int` | `@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 8) https://developer.android.com/reference/androidx/car/app/model/GridTemplate#getItemSize()()` Returns the grid item size, which applies to all grid items in the template. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/model/ItemList` | `https://developer.android.com/reference/androidx/car/app/model/GridTemplate#getSingleList()()` Returns the `https://developer.android.com/reference/androidx/car/app/model/ItemList` instance that contains the grid items to display or ` null` if not set. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/car/app/model/CarText` | `[getTitle](https://developer.android.com/reference/androidx/car/app/model/GridTemplate#getTitle())()` **This method is deprecated.** use `https://developer.android.com/reference/androidx/car/app/model/Header#getTitle()` instead. <br /> |
| `int` | `https://developer.android.com/reference/androidx/car/app/model/GridTemplate#hashCode()()` |
| `boolean` | `https://developer.android.com/reference/androidx/car/app/model/GridTemplate#isLoading()()` Returns whether the template is loading. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/car/app/model/GridTemplate#toString()()` |

## Constants

### ITEM_IMAGE_SHAPE_CIRCLE

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.4.0)

```
@RequiresCarApi(value = 8)
public static final int ITEM_IMAGE_SHAPE_CIRCLE = 2
```

Represents a preference to crop all grid item images into the shape of a circle.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/GridTemplate.Builder#setItemImageShape(int)` |   |

### ITEM_IMAGE_SHAPE_UNSET

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.4.0)

```
@RequiresCarApi(value = 8)
public static final int ITEM_IMAGE_SHAPE_UNSET = 1
```

Represents a preference to keep the images as-is without modifying their shape.

This is the default setting.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/GridTemplate.Builder#setItemImageShape(int)` |   |

### ITEM_SIZE_LARGE

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.4.0)

```
@RequiresCarApi(value = 8)
public static final int ITEM_SIZE_LARGE = 4
```

Represents a large size for all grid items within a template.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/GridTemplate.Builder#setItemSize(int)` |   |

### ITEM_SIZE_MEDIUM

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.4.0)

```
@RequiresCarApi(value = 8)
public static final int ITEM_SIZE_MEDIUM = 2
```

Represents a medium size for all grid items within a template.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/GridTemplate.Builder#setItemSize(int)` |   |

### ITEM_SIZE_SMALL

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.4.0)

```
@RequiresCarApi(value = 8)
public static final int ITEM_SIZE_SMALL = 1
```

Represents a small size for all grid items within a template. This is the default size.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/GridTemplate.Builder#setItemSize(int)` |   |

## Public methods

### equals

```
public boolean equals(@Nullable Object other)
```

### getActionStrip

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0) Deprecated in [1.7.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.7.0)

```
public @Nullable ActionStrip [getActionStrip](https://developer.android.com/reference/androidx/car/app/model/GridTemplate#getActionStrip())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> use `https://developer.android.com/reference/androidx/car/app/model/Header#getEndHeaderActions()` instead.

Returns the `https://developer.android.com/reference/androidx/car/app/model/ActionStrip` for this template or `null` if not set.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/GridTemplate.Builder#setActionStrip(androidx.car.app.model.ActionStrip)` |   |

### getActions

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.4.0)

```
@RequiresCarApi(value = 7)
public @NonNull List<Action> getActions()
```

Returns the list of additional actions.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/GridTemplate.Builder#addAction(androidx.car.app.model.Action)` |   |

### getHeader

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.7.0)

```
public @Nullable Header getHeader()
```

Returns the `https://developer.android.com/reference/androidx/car/app/model/Header` to display in this template.

This method was introduced in API 7, but is backwards compatible even if the client is using API 6 or below.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/GridTemplate.Builder#setHeader(androidx.car.app.model.Header)` |   |

### getHeaderAction

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0) Deprecated in [1.7.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.7.0)

```
public @Nullable Action [getHeaderAction](https://developer.android.com/reference/androidx/car/app/model/GridTemplate#getHeaderAction())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> use `https://developer.android.com/reference/androidx/car/app/model/Header#getStartHeaderAction()` instead.

Returns the `https://developer.android.com/reference/androidx/car/app/model/Action` that is set to be displayed in the header of the template, or `null` if not set.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/GridTemplate.Builder#setHeaderAction(androidx.car.app.model.Action)` |   |

### getItemImageShape

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.4.0)

```
@RequiresCarApi(value = 8)
public int getItemImageShape()
```

Returns the item image shape.

All item images in the grid are cropped into the specified shape.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/GridTemplate.Builder#setItemImageShape(int)` |   |

### getItemSize

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.4.0)

```
@RequiresCarApi(value = 8)
public int getItemSize()
```

Returns the grid item size, which applies to all grid items in the template.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/GridTemplate.Builder#setItemSize(int)` |   |

### getSingleList

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public @Nullable ItemList getSingleList()
```

Returns the `https://developer.android.com/reference/androidx/car/app/model/ItemList` instance that contains the grid items to display or `
null` if not set.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/GridTemplate.Builder#setSingleList(androidx.car.app.model.ItemList)` |   |

### getTitle

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0) Deprecated in [1.7.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.7.0)

```
public @Nullable CarText [getTitle](https://developer.android.com/reference/androidx/car/app/model/GridTemplate#getTitle())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> use `https://developer.android.com/reference/androidx/car/app/model/Header#getTitle()` instead.

Returns the title of the template or `null` if not set.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/GridTemplate.Builder#setTitle(java.lang.CharSequence)` |   |

### hashCode

```
public int hashCode()
```

### isLoading

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

```
public boolean isLoading()
```

Returns whether the template is loading.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/model/GridTemplate.Builder#setLoading(boolean)` |   |

### toString

```
public @NonNull String toString()
```