# ConversationItem.Builder

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/messaging/model/ConversationItem.java+class:androidx.car.app.messaging.model.ConversationItem.Builder) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.3.0)

*** ** * ** ***


```
public final class ConversationItem.Builder
```

<br />

*** ** * ** ***

A builder for `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem`

## Summary

| ### Public constructors |
|---|
| `[Builder](https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder#Builder())()` **This method is deprecated.** Returns an empty `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder` instance. <br /> |
| `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder#Builder(androidx.car.app.messaging.model.ConversationItem)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem other)` Returns a builder from the given `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem`. |
| `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder#Builder(java.lang.String,androidx.car.app.model.CarText,androidx.core.app.Person,java.util.List<androidx.car.app.messaging.model.CarMessage>,androidx.car.app.messaging.model.ConversationCallback)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html id, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarText title, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/Person self, @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/messaging/model/CarMessage> messages, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationCallback conversationCallback )` Creates a `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder` instance with the provided required params. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder` | `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder#addAction(androidx.car.app.model.Action)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/Action action)` Adds an additional action for the conversation. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem` | `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder#build()()` Returns a new `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem` instance defined by this builder |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder` | `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder#setConversationCallback(androidx.car.app.messaging.model.ConversationCallback)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationCallback conversationCallback )` Sets a `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationCallback` for the conversation |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder` | `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder#setGroupConversation(boolean)(boolean isGroupConversation)` Specifies whether this conversation involves 3+ participants (a "group" conversation) |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder` | `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder#setIcon(androidx.car.app.model.CarIcon)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarIcon icon)` Sets a `https://developer.android.com/reference/androidx/car/app/model/CarIcon` for the conversation |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder` | `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder#setId(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html id)` Specifies a unique identifier for the conversation |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder` | `@https://developer.android.com/reference/androidx/car/app/annotations/RequiresCarApi(value = 8) https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder#setIndexable(boolean)(boolean indexable)` Sets whether this item can be included in indexed lists. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder` | `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder#setMessages(java.util.List<androidx.car.app.messaging.model.CarMessage>)(@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/messaging/model/CarMessage> messages)` Specifies a list of messages for the conversation |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder` | `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder#setSelf(androidx.core.app.Person)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/Person self)` Sets a `https://developer.android.com/reference/androidx/core/app/Person` for the conversation |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder` | `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder#setTitle(androidx.car.app.model.CarText)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarText title)` Sets the title of the conversation |

## Public constructors

### Builder

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

```
public [Builder](https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder#Builder())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Returns an empty `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder` instance.

### Builder

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

```
public Builder(@NonNull ConversationItem other)
```

Returns a builder from the given `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem`.

### Builder

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

```
public Builder(
    @NonNull String id,
    @NonNull CarText title,
    @NonNull Person self,
    @NonNull List<CarMessage> messages,
    @NonNull ConversationCallback conversationCallback
)
```

Creates a `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem.Builder` instance with the provided required params.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html id` | Specifies a unique identifier for the conversation IDs may be used for a variety of purposes, including... - Distinguishing new `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem`s from updated `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem`s in the UI, when data is refreshed - Identifying `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem`s in "mark as read" / "reply" callbacks |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/CarText title` | Title of the conversation |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/core/app/Person self` | `https://developer.android.com/reference/androidx/core/app/Person` for the conversation The `https://developer.android.com/reference/androidx/core/app/Person` must specify a non-null `https://developer.android.com/reference/androidx/core/app/Person.Builder#setName(java.lang.CharSequence)` and `https://developer.android.com/reference/androidx/core/app/Person.Builder#setKey(java.lang.String)`. |
| `@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/messaging/model/CarMessage> messages` | Specifies a list of messages for the conversation The messages should be sorted from oldest to newest and should not contain any null values. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationCallback conversationCallback` | `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationCallback` for the conversation |

## Public methods

### addAction

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

```
public @NonNull ConversationItem.Builder addAction(@NonNull Action action)
```

Adds an additional action for the conversation.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if `action` is `null` |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `action` contains unsupported Action types, exceeds the maximum number of allowed actions (1) or does not contain a valid `https://developer.android.com/reference/androidx/car/app/model/CarIcon`. |

### build

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

```
public @NonNull ConversationItem build()
```

Returns a new `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem` instance defined by this builder

### setConversationCallback

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

```
public @NonNull ConversationItem.Builder setConversationCallback(
    @NonNull ConversationCallback conversationCallback
)
```

Sets a `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationCallback` for the conversation

### setGroupConversation

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

```
public @NonNull ConversationItem.Builder setGroupConversation(boolean isGroupConversation)
```

Specifies whether this conversation involves 3+ participants (a "group" conversation)

If unspecified, conversations are assumed to have exactly two participants (a "1:1" conversation)

UX presentation may differ slightly between group and 1:1 conversations. As a historical example, message readout may include sender names for group conversations, but omit them for 1:1 conversations.

### setIcon

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

```
public @NonNull ConversationItem.Builder setIcon(@NonNull CarIcon icon)
```

Sets a `https://developer.android.com/reference/androidx/car/app/model/CarIcon` for the conversation

### setId

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

```
public @NonNull ConversationItem.Builder setId(@NonNull String id)
```

Specifies a unique identifier for the conversation

IDs may be used for a variety of purposes, including...

- Distinguishing new `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem`s from updated `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem`s in the UI, when data is refreshed
- Identifying `https://developer.android.com/reference/androidx/car/app/messaging/model/ConversationItem`s in "mark as read" / "reply" callbacks

### setIndexable

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

```
@RequiresCarApi(value = 8)
public @NonNull ConversationItem.Builder setIndexable(boolean indexable)
```

Sets whether this item can be included in indexed lists. By default, this is set to `true`.

The host creates indexed lists to help users navigate through long lists more easily by sorting, filtering, or some other means.

For example, a messaging app may show conversations by last message received. If the app provides these conversations via the `SectionedItemTemplate` and enables `#isAlphabeticalIndexingAllowed`, the user will be able to jump to their conversations that start with a given letter they chose. The messaging app can choose to hide, for example, service messages from this filtered list by setting this `
#setIndexable(false)`.

Individual items can be set to be included or excluded from filtered lists, but it's also possible to enable/disable the creation of filtered lists as a whole via the template's API (eg. `SectionedItemTemplate
.Builder#setAlphabeticalIndexingAllowed(Boolean)`).

### setMessages

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

```
public @NonNull ConversationItem.Builder setMessages(@NonNull List<CarMessage> messages)
```

Specifies a list of messages for the conversation

The messages should be sorted from oldest to newest and should not contain any null values.

### setSelf

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

```
public @NonNull ConversationItem.Builder setSelf(@NonNull Person self)
```

Sets a `https://developer.android.com/reference/androidx/core/app/Person` for the conversation

The `https://developer.android.com/reference/androidx/core/app/Person` must specify a non-null `https://developer.android.com/reference/androidx/core/app/Person.Builder#setName(java.lang.CharSequence)` and `https://developer.android.com/reference/androidx/core/app/Person.Builder#setKey(java.lang.String)`.

### setTitle

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

```
public @NonNull ConversationItem.Builder setTitle(@NonNull CarText title)
```

Sets the title of the conversation