Skip to main content
The UI Kit provides two levels of event handling: component-level callbacks set directly on a View instance, and global events registered via static listener methods on event classes.

Component-Level Callbacks

Click Callbacks

SetterTriggered When
setOnItemClick(OnItemClick<Conversation>)User taps a list item
setOnItemLongClick(OnItemLongClick<Conversation>)User long-presses a list item
setOnBackPressListener(OnBackPress)User taps the back button
setOnSearchClickListener(OnSearchClick)User taps the search icon
conversations.setOnItemClick { conversation, position ->
    // Navigate to chat screen
    openChat(conversation)
}

conversations.setOnItemLongClick { conversation, position ->
    // Show custom context menu
    showCustomMenu(conversation)
}

conversations.setOnBackPressListener {
    // Handle back navigation
    finish()
}

conversations.setOnSearchClickListener {
    // Open search screen
    openSearch()
}

Error Callback

Use setOnError to handle component-level errors:
conversations.setOnError { exception ->
    Log.e("Conversations", "Error: ${exception.message}")
}

Selection Mode

Enable single or multi-select on list components:
MethodDescription
setSelectionMode(UIKitConstants.SelectionMode)Set the selection mode: NONE, SINGLE, or MULTIPLE
setOnSelect(OnSelection<Conversation>)Callback when selection changes
getSelectedConversations()Get the list of currently selected conversations
clearSelection()Clear all selections
selectConversation(Conversation, SelectionMode)Programmatically select a conversation
// Enable multi-select mode
conversations.setSelectionMode(UIKitConstants.SelectionMode.MULTIPLE)

// Listen for selection changes
conversations.setOnSelect { selectedList ->
    updateToolbar(selectedList.size)
}

// Get selected items
val selected = conversations.getSelectedConversations()

// Clear selection
conversations.clearSelection()

Global Events

Global events are fired by the UI Kit when actions happen anywhere in the app. Register listeners using the static listener registration methods on each event class (addListener, addGroupListener, or addUserListener depending on the class).
Event ClassFires When
CometChatConversationEventsConversation is deleted or updated
CometChatMessageEventsMessages are sent, edited, deleted, or reacted to
CometChatGroupEventsGroups are created, updated, members added/removed
CometChatUserEventsUsers are blocked/unblocked
CometChatUIEventsUI-level events like opening chat, showing dialogs
CometChatCallEventsCalls are initiated, accepted, rejected, or ended
Each listener is registered with a unique String tag so it can be removed later.

Component-Level vs Global Events

  • Component-level callbacks (e.g., setOnItemClick) are set on a specific View instance and only fire for that component.
  • Global events (e.g., CometChatMessageEvents.addListener) are static and fire regardless of which component triggered the action. Use them for cross-component coordination.
// Register a global message event listener
CometChatMessageEvents.addListener("unique-listener-id",
    object : CometChatMessageEvents() {
        override fun ccMessageSent(baseMessage: BaseMessage, status: Int) {
            // Handle sent message across the app
        }

        override fun onMessageDeleted(message: BaseMessage) {
            // Handle deleted message
        }
    }
)

// Remove the listener when done
CometChatMessageEvents.removeListener("unique-listener-id")