CometChatConversations is a list component. It renders recent conversations and emits the selected Conversation via setOnItemClick. Wire it to CometChatMessageHeader, CometChatMessageList, and CometChatMessageComposer to build a standard chat layout.
Kotlin
Java
XML
ChatActivity.kt
class ChatActivity : AppCompatActivity() { private lateinit var conversations: CometChatConversations private lateinit var messageHeader: CometChatMessageHeader private lateinit var messageList: CometChatMessageList private lateinit var messageComposer: CometChatMessageComposer override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_chat) conversations = findViewById(R.id.conversations) messageHeader = findViewById(R.id.message_header) messageList = findViewById(R.id.message_list) messageComposer = findViewById(R.id.message_composer) conversations.setOnItemClick { view, position, conversation -> if (conversation.conversationType == CometChatConstants.CONVERSATION_TYPE_USER) { val user = conversation.conversationWith as User messageHeader.setUser(user) messageList.setUser(user) messageComposer.setUser(user) } else { val group = conversation.conversationWith as Group messageHeader.setGroup(group) messageList.setGroup(group) messageComposer.setGroup(group) } } }}
ChatActivity.java
public class ChatActivity extends AppCompatActivity { private CometChatConversations conversations; private CometChatMessageHeader messageHeader; private CometChatMessageList messageList; private CometChatMessageComposer messageComposer; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat); conversations = findViewById(R.id.conversations); messageHeader = findViewById(R.id.message_header); messageList = findViewById(R.id.message_list); messageComposer = findViewById(R.id.message_composer); conversations.setOnItemClick((view, position, conversation) -> { if (CometChatConstants.CONVERSATION_TYPE_USER.equals(conversation.getConversationType())) { User user = (User) conversation.getConversationWith(); messageHeader.setUser(user); messageList.setUser(user); messageComposer.setUser(user); } else { Group group = (Group) conversation.getConversationWith(); messageHeader.setGroup(group); messageList.setGroup(group); messageComposer.setGroup(group); } }); }}
Prerequisites: CometChat SDK initialized with CometChatUIKit.init(), a user logged in, and the cometchat-chat-uikit-android dependency added.To add programmatically in an Activity:
Kotlin
Java
YourActivity.kt
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(CometChatConversations(this))}
Default page size is 30. The component uses infinite scroll — the next page loads as the user scrolls to the bottom. Refer to ConversationsRequestBuilder for the full builder API.
Actions and Events
Callback Methods
setOnItemClick
Fires when a conversation row is tapped. Primary navigation hook — set the active conversation and render the message view.
What this does: Replaces the default item-click behavior. When a user taps a conversation, your custom lambda executes instead of the built-in navigation.
setOnItemLongClick
Fires when a conversation row is long-pressed. Use for additional actions like delete or select.
What this does: Registers a callback that fires when the user selects one or more conversations. The callback receives the list of selected Conversation objects.
setOnError
Fires on internal errors (network failure, auth issue, SDK exception).
What this does: Registers an error listener. If the component encounters an error (e.g., network failure), your callback receives the CometChatException.
setOnLoad
Fires when the list is successfully fetched and loaded.
Kotlin
Java
YourActivity.kt
cometchatConversations.setOnLoad(object : OnLoad<Conversation?> { override fun onLoad(list: MutableList<Conversation?>?) { }})
YourActivity.java
cometchatConversations.setOnLoad(list -> {});
What this does: Registers a callback that fires after the conversation list is fetched and rendered. The callback receives the list of loaded Conversation objects.
setOnEmpty
Fires when the list is empty, enabling custom handling such as showing a placeholder.
Kotlin
Java
YourActivity.kt
cometchatConversations.setOnEmpty{ }
YourActivity.java
cometchatConversations.setOnEmpty(() -> { });
What this does: Registers a callback that fires when the conversation list has no items. Use this to show a custom empty-state message or trigger other logic.
setOnSearchClickListener
Fires when the user taps the search icon in the toolbar.
What this does: Overrides the default search icon tap behavior. When the user taps the search icon, your custom logic runs instead.
Verify: After setting an action callback, trigger the corresponding user interaction (tap, long-press, back, select, search) and confirm your custom logic executes instead of the default behavior.
Global UI Events
CometChatConversationEvents emits events subscribable from anywhere in the application. Add a listener and remove it when no longer needed.
Automatic: new messages, typing indicators, receipts, user presence, group membership changes.
Manual: deleting a conversation via the SDK directly (not through the component’s context menu) requires emitting CometChatConversationEvents.ccConversationDeleted for the UI to update.
Functionality
Small functional customizations such as toggling visibility of UI elements, setting custom sounds, and configuring selection modes.
Methods
Description
Code
setBackIconVisibility
Toggles visibility for the back button in the app bar
.setBackIconVisibility(View.VISIBLE);
setToolbarVisibility
Toggles visibility for the toolbar in the app bar
.setToolbarVisibility(View.GONE);
setLoadingStateVisibility
Hides the loading state while fetching conversations
.setLoadingStateVisibility(View.GONE);
setDeleteConversationOptionVisibility
Toggles visibility for the delete option on long press
Sets the placeholder text for the search input field
.setSearchPlaceholderText("Enter search term");
Verify: After calling a visibility method, confirm the corresponding UI element is shown or hidden. After calling disableSoundForMessages(true), confirm no sound plays on incoming messages.
Custom View Slots
Each slot replaces a section of the default UI. Slots that accept a Conversation parameter receive the conversation object for that row via the ConversationsViewHolderListener pattern (createView + bindView).
Slot
Method
Replaces
Leading view
setLeadingView(ConversationsViewHolderListener)
Avatar / left section
Title view
setTitleView(ConversationsViewHolderListener)
Name / title text
Subtitle view
setSubtitleView(ConversationsViewHolderListener)
Last message preview
Trailing view
setTrailingView(ConversationsViewHolderListener)
Timestamp / badge / right section
Item view
setItemView(ConversationsViewHolderListener)
Entire list item row
Loading view
setLoadingView(@LayoutRes int)
Loading spinner
Empty view
setEmptyView(@LayoutRes int)
Empty state
Error view
setErrorView(@LayoutRes int)
Error state
Overflow menu
setOverflowMenu(View)
Toolbar menu
Options (replace)
setOptions(Function2)
Long-press context menu (replaces defaults)
Options (append)
addOptions(Function2)
Long-press context menu (appends to defaults)
setLeadingView
Replace the avatar / left section. Typing-aware avatar example.
What this does: Registers a ConversationsViewHolderListener that provides a custom view for the leading (left) area of each conversation item. createView inflates your layout, and bindView populates it with conversation data.
The following example shows a custom leading view with a chat-dots icon for typing indicators and an avatar with status indicator:
What this does: Defines a custom trailing view layout with a MaterialCardView containing two TextView elements for displaying the time value and unit (e.g., “5” and “Min ago”).
Inflate and bind with color-coded time badges:
Kotlin
Java
cometchatConversations.setTrailingView(object : ConversationsViewHolderListener() { override fun createView(context: Context?, listItem: CometchatConversationsListItemsBinding?): View { return LayoutInflater.from(context).inflate(R.layout.custom_tail_view, null) } override fun bindView( context: Context, createdView: View, conversation: Conversation, holder: RecyclerView.ViewHolder, conversationList: List<Conversation>, position: Int ) { val card = createdView.findViewById<MaterialCardView>(R.id.card) val tvHours = createdView.findViewById<TextView>(R.id.hours) val tvMessage = createdView.findViewById<TextView>(R.id.time_title) var timestamp = conversation.updatedAt * 1000 if (timestamp.toString().length == 10) { timestamp *= 1000 } val now = Calendar.getInstance() val lastSeen = Calendar.getInstance() lastSeen.timeInMillis = timestamp val diffInMillis = now.timeInMillis - lastSeen.timeInMillis val diffInMinutes = TimeUnit.MILLISECONDS.toMinutes(diffInMillis) val diffInHours = TimeUnit.MILLISECONDS.toHours(diffInMillis) if (diffInMinutes == 0L) { tvHours.text = "1" tvMessage.text = "Min ago" card.setCardBackgroundColor(Utils.applyColorWithAlphaValue(Color.parseColor("#6852D6"), 40)) tvMessage.setTextColor(Color.parseColor("#6852D6")) tvHours.setTextColor(Color.parseColor("#6852D6")) } else if (diffInMinutes < 60) { tvHours.text = diffInMinutes.toString() tvMessage.text = "Min ago" card.setCardBackgroundColor(Utils.multiplyColorAlpha(Color.parseColor("#6852D6"), 40)) tvMessage.setTextColor(Color.parseColor("#6852D6")) tvHours.setTextColor(Color.parseColor("#6852D6")) } else if (diffInHours < 10) { tvHours.text = diffInHours.toString() tvMessage.text = "Hr ago" tvMessage.setTextColor(Color.parseColor("#FFAB00")) tvHours.setTextColor(Color.parseColor("#FFAB00")) card.setCardBackgroundColor(Utils.multiplyColorAlpha(Color.parseColor("#FFAB00"), 40)) } else if (diffInHours < 1000) { tvHours.text = diffInHours.toString() tvMessage.text = "Hr ago" tvMessage.setTextColor(Color.parseColor("#F44649")) tvHours.setTextColor(Color.parseColor("#F44649")) card.setCardBackgroundColor(Utils.multiplyColorAlpha(Color.parseColor("#F44649"), 40)) } } })
What this does: Defines a custom title layout with the conversation name and an inline user status message.
Kotlin
Java
cometchatConversations.setTitleView(object : ConversationsViewHolderListener() { override fun createView(context: Context?, listItem: CometchatConversationsListItemsBinding?): View { return LayoutInflater.from(context).inflate(R.layout.custom_title_view, null) } override fun bindView( context: Context, createdView: View, conversation: Conversation, holder: RecyclerView.ViewHolder, conversationList: List<Conversation>, position: Int ) { val name = createdView.findViewById<TextView>(R.id.name) val status = createdView.findViewById<TextView>(R.id.status) name.text = ConversationsUtils.getConversationTitle(conversation) if (conversation.conversationType == CometChatConstants.RECEIVER_TYPE_USER) { status.visibility = View.VISIBLE status.text = "• " + (conversation.conversationWith as User).statusMessage } else { status.visibility = View.GONE } } })
cometchatConversations.setTitleView(new ConversationsViewHolderListener() { @Override public View createView(Context context, CometchatConversationsListItemsBinding listItem) { return LayoutInflater.from(context).inflate(R.layout.custom_title_view, null); } @Override public void bindView(Context context, View createdView, Conversation conversation, RecyclerView.ViewHolder holder, List<Conversation> conversationList, int position) { TextView name = createdView.findViewById(R.id.name); TextView status = createdView.findViewById(R.id.status); name.setText(ConversationsUtils.getConversationTitle(conversation)); if (conversation.getConversationType().equals(CometChatConstants.RECEIVER_TYPE_USER)) { status.setVisibility(View.VISIBLE); status.setText("• " + ((User) conversation.getConversationWith()).getStatusMessage()); } else { status.setVisibility(View.GONE); } } });
What this does: Registers a ConversationsViewHolderListener that provides a custom title view for each conversation item. The example inflates a layout with the conversation name and an inline user status message. For group conversations, the status is hidden.
cometchatConversations.setSubtitleView(object : ConversationsViewHolderListener() { override fun createView( context: Context?, listItem: CometchatConversationsListItemsBinding? ): View { return TextView(context) } override fun bindView( context: Context, createdView: View, conversation: Conversation, holder: RecyclerView.ViewHolder, conversationList: List<Conversation>, position: Int ) { val tvSubtitle = createdView as TextView tvSubtitle.text = "Last Active at: " + SimpleDateFormat("dd/MM/yyyy, HH:mm:ss").format( conversation.updatedAt * 1000 ) tvSubtitle.setTextColor(Color.BLACK) } })
YourActivity.java
cometchatConversations.setSubtitleView(new ConversationsViewHolderListener() { @Override public View createView(Context context, CometchatConversationsListItemsBinding listItem) { return new TextView(context); } @Override public void bindView(Context context, View createdView, Conversation conversation, RecyclerView.ViewHolder holder, List<Conversation> conversationList, int position) { TextView tvSubtitle = (TextView) createdView; tvSubtitle.setText("Last Active at: "+new SimpleDateFormat("dd/MM/yyyy, HH:mm:ss").format(conversation.getUpdatedAt() * 1000)); tvSubtitle.setTextColor(Color.BLACK); } });
What this does: Registers a ConversationsViewHolderListener that provides a custom subtitle view for each conversation item. The example creates a TextView showing the last active timestamp formatted as “dd/MM/yyyy, HH:mm:ss”.
What this does: Defines a custom list item layout with a CometChatAvatar, status indicator, conversation name, and date — providing a compact, single-line conversation item design.
Inflate the XML and bind:
Kotlin
Java
cometchatConversations.setItemView(object : ConversationsViewHolderListener() { override fun createView( context: Context?, listItem: CometchatConversationsListItemsBinding? ): View { return LayoutInflater.from(context) .inflate(R.layout.custom_list_item_view, null, false) } override fun bindView( context: Context, createdView: View, conversation: Conversation, holder: RecyclerView.ViewHolder, conversationList: List<Conversation>, position: Int ) { val avatar = createdView.findViewById<CometChatAvatar>(R.id.custom_avatar) val title = createdView.findViewById<TextView>(R.id.tvName) val tvDate = createdView.findViewById<TextView>(R.id.tvDate) val name = ConversationsUtils.getConversationTitle(conversation) title.text = name avatar.setStyle(com.cometchat.chatuikit.R.style.CometChatAvatarStyle) avatar.avatarPlaceHolderTextAppearance = com.cometchat.chatuikit.R.style.CometChatTextAppearanceHeading4_Bold avatar.setAvatar(name, ConversationsUtils.getConversationAvatar(conversation)) val simpleDateFormat = SimpleDateFormat("hh:mm a") val date = simpleDateFormat.format(conversation.updatedAt * 1000) tvDate.text = date } })
YourActivity.java
cometchatConversations.setItemView(new ConversationsViewHolderListener() { @Override public View createView(Context context, CometchatConversationsListItemsBinding listItem) { return LayoutInflater.from(context).inflate(R.layout.custom_list_item_view, null, false); } @Override public void bindView(Context context, View createdView, Conversation conversation, RecyclerView.ViewHolder holder, List<Conversation> conversationList, int position) { CometChatAvatar avatar = createdView.findViewById(R.id.custom_avatar); TextView title = createdView.findViewById(R.id.tvName); TextView tvDate = createdView.findViewById(R.id.tvDate); String name = ConversationsUtils.getConversationTitle(conversation); title.setText(name); avatar.setStyle(com.cometchat.chatuikit.R.style.CometChatAvatarStyle); avatar.setAvatarPlaceHolderTextAppearance(com.cometchat.chatuikit.R.style.CometChatTextAppearanceHeading4_Bold); avatar.setAvatar(name, ConversationsUtils.getConversationAvatar(conversation)); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mm a"); String date = simpleDateFormat.format(conversation.getUpdatedAt() * 1000); tvDate.setText(date); } });
What this does: Registers a ConversationsViewHolderListener that replaces the entire list item row. The example inflates a compact layout with an avatar, name, and date — replacing the default multi-line conversation item.
setDateTimeFormatter
Custom date/time formatting for conversation timestamps. Implement the DateTimeFormatterCallback interface to control how each time range is displayed:
Method
Called when
time(long timestamp)
Custom full timestamp format
today(long timestamp)
Message is from today
yesterday(long timestamp)
Message is from yesterday
lastWeek(long timestamp)
Message is from the past week
otherDays(long timestamp)
Message is older than a week
minute(long timestamp)
Exactly 1 minute ago
minutes(long diffInMinutesFromNow, long timestamp)
Multiple minutes ago (e.g., “5 minutes ago”)
hour(long timestamp)
Exactly 1 hour ago
hours(long diffInHourFromNow, long timestamp)
Multiple hours ago (e.g., “2 hours ago”)
Kotlin
Java
cometchatConversations.setDateTimeFormatter(object : DateTimeFormatterCallback { private val fullTimeFormatter = SimpleDateFormat("hh:mm a", Locale.getDefault()) private val dateFormatter = SimpleDateFormat("dd MMM yyyy", Locale.getDefault()) override fun time(timestamp: Long): String { return fullTimeFormatter.format(Date(timestamp)) } override fun today(timestamp: Long): String { return "Today" } override fun yesterday(timestamp: Long): String { return "Yesterday" } override fun lastWeek(timestamp: Long): String { return "Last Week" } override fun otherDays(timestamp: Long): String { return dateFormatter.format(Date(timestamp)) } override fun minutes(diffInMinutesFromNow: Long, timestamp: Long): String { return "$diffInMinutesFromNow mins ago" } override fun hours(diffInHourFromNow: Long, timestamp: Long): String { return "$diffInHourFromNow hrs ago" } })
cometchatConversations.setDateTimeFormatter(new DateTimeFormatterCallback() { private final SimpleDateFormat fullTimeFormatter = new SimpleDateFormat("hh:mm a", Locale.getDefault()); private final SimpleDateFormat dateFormatter = new SimpleDateFormat("dd MMM yyyy", Locale.getDefault()); @Override public String time(long timestamp) { return fullTimeFormatter.format(new Date(timestamp)); } @Override public String today(long timestamp) { return "Today"; } @Override public String yesterday(long timestamp) { return "Yesterday"; } @Override public String lastWeek(long timestamp) { return "Last Week"; } @Override public String otherDays(long timestamp) { return dateFormatter.format(new Date(timestamp)); } @Override public String minutes(long diffInMinutesFromNow, long timestamp) { return diffInMinutesFromNow + " mins ago"; } @Override public String hours(long diffInHourFromNow, long timestamp) { return diffInHourFromNow + " hrs ago"; } });
setOptions
Replace the long-press context menu entirely.Generic signature:
val mentionFormatter = CometChatMentionsFormatter(context)mentionFormatter.setConversationsMentionTextStyle(context, R.style.CustomConversationsMentionsStyle)val textFormatters: MutableList<CometChatTextFormatter> = ArrayList()textFormatters.add(mentionFormatter)cometChatConversations.setTextFormatters(textFormatters)
CometChatMentionsFormatter mentionFormatter = new CometChatMentionsFormatter(context);mentionFormatter.setConversationsMentionTextStyle(context, R.style.CustomConversationsMentionsStyle);List<CometChatTextFormatter> textFormatters = new ArrayList<>();textFormatters.add(mentionFormatter);cometChatConversations.setTextFormatters(textFormatters);
setLoadingView
Sets a custom loading view displayed when data is being fetched.
What this does: Replaces the default error state with your custom layout resource. The custom view displays when the component encounters an error during data fetching.
setDateFormat
Customizes the date format used for displaying timestamps in conversations.Generic signature:
What this does: Defines a popup menu layout with options for creating a conversation, viewing the user profile, logging out, and displaying the app version.
Inflate the view and pass it to setOverflowMenu:
Kotlin
Java
class YourActivity : AppCompatActivity() { private lateinit var cometChatConversations: CometChatConversations override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) cometChatConversations = findViewById(R.id.conversations) cometChatConversations.setOverflowMenu(logoutView) } private val logoutView: View? get() { val user = CometChatUIKit.getLoggedInUser() if (user != null) { val cometchatAvatar = CometChatAvatar(this) cometchatAvatar.setAvatar(user.name, user.avatar) val layoutParams = LinearLayout.LayoutParams( resources.getDimensionPixelSize(com.cometchat.chatuikit.R.dimen.cometchat_40dp), resources.getDimensionPixelSize(com.cometchat.chatuikit.R.dimen.cometchat_40dp)) layoutParams.layoutDirection = Gravity.CENTER_VERTICAL cometchatAvatar.layoutParams = layoutParams cometchatAvatar.setOnClickListener { showCustomMenu(cometChatConversations.binding.toolbarLayout) } return cometchatAvatar } return null } private fun showCustomMenu(anchorView: View) { val popupMenuBinding = UserProfilePopupMenuLayoutBinding.inflate(LayoutInflater.from(this)) val popupWindow = PopupWindow(popupMenuBinding.root, resources.getDimensionPixelSize(com.cometchat.chatuikit.R.dimen.cometchat_250dp), LinearLayout.LayoutParams.WRAP_CONTENT, true) popupMenuBinding.tvUserName.text = CometChatUIKit.getLoggedInUser().name val version = "V" + BuildConfig.VERSION_NAME + "(" + BuildConfig.VERSION_CODE + ")" popupMenuBinding.tvVersion.text = version popupMenuBinding.tvCreateConversation.setOnClickListener { popupWindow.dismiss() } popupMenuBinding.tvUserName.setOnClickListener { popupWindow.dismiss() } popupMenuBinding.tvLogout.setOnClickListener { popupWindow.dismiss() } popupWindow.elevation = 5f val endMargin = resources.getDimensionPixelSize(com.cometchat.chatuikit.R.dimen.cometchat_margin_2) val anchorWidth = anchorView.width val offsetX = anchorWidth - popupWindow.width - endMargin popupWindow.showAsDropDown(anchorView, offsetX, 0) }}
public class YourActivity extends AppCompatActivity { private CometChatConversations cometChatConversations; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); cometChatConversations = findViewById(R.id.conversations); cometChatConversations.setOverflowMenu(getLogoutView()); } private View getLogoutView() { User user = CometChatUIKit.getLoggedInUser(); if (user != null) { CometChatAvatar cometchatAvatar = new CometChatAvatar(this); cometchatAvatar.setAvatar(user.getName(), user.getAvatar()); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( getResources().getDimensionPixelSize(com.cometchat.chatuikit.R.dimen.cometchat_40dp), getResources().getDimensionPixelSize(com.cometchat.chatuikit.R.dimen.cometchat_40dp)); layoutParams.setLayoutDirection(Gravity.CENTER_VERTICAL); cometchatAvatar.setLayoutParams(layoutParams); cometchatAvatar.setOnClickListener(v -> { showCustomMenu(cometChatConversations.getBinding().toolbarLayout); }); return cometchatAvatar; } return null; } private void showCustomMenu(View anchorView) { UserProfilePopupMenuLayoutBinding popupMenuBinding = UserProfilePopupMenuLayoutBinding.inflate(LayoutInflater.from(this)); final PopupWindow popupWindow = new PopupWindow(popupMenuBinding.getRoot(), getResources().getDimensionPixelSize(com.cometchat.chatuikit.R.dimen.cometchat_250dp), LinearLayout.LayoutParams.WRAP_CONTENT, true); popupMenuBinding.tvUserName.setText(CometChatUIKit.getLoggedInUser().getName()); String version = "V" + BuildConfig.VERSION_NAME + "(" + BuildConfig.VERSION_CODE + ")"; popupMenuBinding.tvVersion.setText(version); popupMenuBinding.tvCreateConversation.setOnClickListener(view -> popupWindow.dismiss()); popupMenuBinding.tvUserName.setOnClickListener(view -> popupWindow.dismiss()); popupMenuBinding.tvLogout.setOnClickListener(view -> popupWindow.dismiss()); popupWindow.setElevation(5); int endMargin = getResources().getDimensionPixelSize(com.cometchat.chatuikit.R.dimen.cometchat_margin_2); int anchorWidth = anchorView.getWidth(); int offsetX = anchorWidth - popupWindow.getWidth() - endMargin; popupWindow.showAsDropDown(anchorView, offsetX, 0); }}
What this does: Creates a complete overflow menu implementation. An avatar of the logged-in user is set as the overflow menu view. When tapped, it shows a popup window with options for creating a conversation, viewing the user profile, logging out, and displaying the app version.
Verify: After setting any custom view slot, confirm the custom view renders in the correct position within the conversation list item, and the data binding populates correctly for each conversation.
val builder = ConversationsRequest.ConversationsRequestBuilder() .setConversationType(CometChatConstants.CONVERSATION_TYPE_USER)cometChatConversations.setConversationsRequestBuilder(builder)
ConversationsRequest.ConversationsRequestBuilder builder = new ConversationsRequest.ConversationsRequestBuilder();builder.setConversationType(CometChatConstants.CONVERSATION_TYPE_USER);cometChatConversations.setConversationsRequestBuilder(builder);
Advanced Methods
Programmatic Selection
selectConversation
Programmatically selects or deselects a conversation. Works with both SINGLE and MULTIPLE selection modes.
Kotlin
Java
// Select a conversation in single-select modecometChatConversations.selectConversation(conversation, UIKitConstants.SelectionMode.SINGLE)// Select a conversation in multi-select modecometChatConversations.selectConversation(conversation, UIKitConstants.SelectionMode.MULTIPLE)
// Select a conversation in single-select modecometChatConversations.selectConversation(conversation, UIKitConstants.SelectionMode.SINGLE);// Select a conversation in multi-select modecometChatConversations.selectConversation(conversation, UIKitConstants.SelectionMode.MULTIPLE);
In SINGLE mode, selecting a new conversation replaces the previous selection. In MULTIPLE mode, calling this on an already-selected conversation deselects it (toggle behavior).
clearSelection
Clears all selected conversations and resets the selection UI.
Kotlin
Java
cometChatConversations.clearSelection()
cometChatConversations.clearSelection();
getSelectedConversations
Returns the list of currently selected Conversation objects.
Kotlin
Java
val selected = cometChatConversations.selectedConversations
When using multi-select mode, a horizontal list of selected conversations can be shown above the main list.
Method
Type
Description
setSelectedConversationsListVisibility
int (View.VISIBLE / View.GONE)
Show or hide the selected conversations strip
setSelectedConversationAvatarStyle
@StyleRes int
Avatar style for selected conversation chips
setSelectedConversationItemTextColor
@ColorInt int
Text color for selected conversation names
setSelectedConversationItemTextAppearance
@StyleRes int
Text appearance for selected conversation names
setSelectedConversationItemRemoveIcon
Drawable
Icon for the remove button on each chip
setSelectedConversationItemRemoveIconTint
@ColorInt int
Tint color for the remove icon
Search Input Customization
The built-in search box can be customized programmatically:
Method
Type
Description
setSearchInputText
String
Sets the search input text programmatically
setSearchPlaceholderText
String
Sets the placeholder text for the search input
setSearchInputTextColor
@ColorInt int
Text color of the search input
setSearchInputTextAppearance
@StyleRes int
Text appearance of the search input
setSearchInputPlaceHolderTextColor
@ColorInt int
Placeholder text color
setSearchInputPlaceHolderTextAppearance
@StyleRes int
Placeholder text appearance
setSearchInputStartIcon
Drawable
Leading icon in the search box
setSearchInputStartIconTint
@ColorInt int
Tint for the leading icon
setSearchInputEndIcon
Drawable
Trailing icon in the search box
setSearchInputEndIconTint
@ColorInt int
Tint for the trailing icon
setSearchInputEndIconVisibility
int
Visibility of the trailing icon
setSearchInputStrokeWidth
@Dimension int
Stroke width of the search box border
setSearchInputStrokeColor
@ColorInt int
Stroke color of the search box border
setSearchInputBackgroundColor
@ColorInt int
Background color of the search box
setSearchInputCornerRadius
@Dimension int
Corner radius of the search box
Internal Access
These methods provide direct access to internal components for advanced use cases.
Method
Returns
Description
getRecyclerView()
RecyclerView
The underlying RecyclerView displaying conversations
getViewModel()
ConversationsViewModel
The ViewModel managing conversation data and state
getConversationsAdapter()
ConversationsAdapter
The adapter powering the RecyclerView
setAdapter(ConversationsAdapter)
void
Replaces the default adapter with a custom one
getBinding()
CometchatConversationsListViewBinding
The ViewBinding for the component’s root layout
Use these only when the standard API is insufficient. Directly manipulating the adapter or ViewModel may conflict with the component’s internal state management.