Documentation Index
Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
List-based components like 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
val conversations = CometChatConversations(context)
val adapter: ConversationsAdapter = conversations.getConversationsAdapter()
CometChatConversations conversations = new CometChatConversations(context);
ConversationsAdapter adapter = conversations.getConversationsAdapter();
Replacing the Adapter
Use setAdapter to replace the default adapter with a custom implementation:
val customAdapter = ConversationsAdapter(context)
// Configure your custom adapter...
conversations.setAdapter(customAdapter)
ConversationsAdapter customAdapter = new ConversationsAdapter(context);
// Configure your custom adapter...
conversations.setAdapter(customAdapter);
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 |
val adapter = conversations.getConversationsAdapter()
// Get the current list
val currentList = adapter.getConversationsList()
// Add a conversation at the top
adapter.add(0, newConversation)
// Remove a conversation
adapter.remove(conversation)
// Replace the entire list
adapter.setList(filteredConversations)
ConversationsAdapter adapter = conversations.getConversationsAdapter();
// Get the current list
List<Conversation> currentList = adapter.getConversationsList();
// Add a conversation at the top
adapter.add(0, newConversation);
// Remove a conversation
adapter.remove(conversation);
// Replace the entire list
adapter.setList(filteredConversations);
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(...) |
Setting view slots directly on the adapter is useful when you’ve replaced the adapter with 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 |