CometChatConversations use a RecyclerView.Adapter to bind data to list items. You can access the default adapter to manipulate data, or replace it entirely with a custom implementation.
Accessing the Adapter
- Kotlin
- Java
Replacing the Adapter
UsesetAdapter to replace the default adapter with a custom implementation:
- Kotlin
- Java
Data Manipulation API
The adapter provides methods to programmatically manage the list data:| Method | Description |
|---|---|
setList(List<Conversation>) | Replace the entire list |
addList(List<Conversation>) | Append conversations to the end |
add(Conversation) | Add a single conversation to the end |
add(int position, Conversation) | Insert a conversation at a specific position |
remove(int position) | Remove a conversation by position |
remove(Conversation) | Remove a specific conversation |
clear() | Remove all conversations |
updateConversation(Conversation) | Update an existing conversation in place |
getConversationsList() | Get the current list of conversations |
- Kotlin
- Java
View Slots on the Adapter
The adapter exposes the same view slot setters as the View layer. When you set a view slot on the View (e.g.,conversations.setSubtitleView(...)), it delegates to the adapter internally. You can also set view slots directly on the adapter:
| Adapter Method | Equivalent View Method |
|---|---|
adapter.setLeadingView(...) | conversations.setLeadingView(...) |
adapter.setTitleView(...) | conversations.setTitleView(...) |
adapter.setSubtitleView(...) | conversations.setSubtitleView(...) |
adapter.setTrailingView(...) | conversations.setTrailingView(...) |
adapter.setItemView(...) | conversations.setItemView(...) |
setAdapter and need to configure it before attaching.
Adapter Style Propagation
The adapter has its own style setter methods. These are typically called internally by the View layer, but you can use them directly when working with a custom adapter:| Method | Applies To |
|---|---|
setConversationsAvatarStyle(@StyleRes int) | Avatar style for list items |
setConversationsBadgeStyle(@StyleRes int) | Unread badge style |
setConversationsReceiptStyle(@StyleRes int) | Message receipt icon style |
setConversationsDateStyle(@StyleRes int) | Date/time label style |
setConversationsTypingIndicatorStyle(@StyleRes int) | Typing indicator style |
setConversationsStatusIndicatorStyle(@StyleRes int) | Online/offline status indicator style |
Related
- View Slots — Learn the ViewHolderListener pattern used by adapter view slots.
- ViewModel & Data — Manage data at the ViewModel level instead of the adapter.
- Customization Overview — See all customization categories.