Skip to main content

Where It Fits

CometChatUsers is a list component. It renders all available users and emits the selected User via setOnItemClick. Wire it to CometChatMessageHeader, CometChatMessageList, and CometChatMessageComposer to build a direct messaging layout.
ChatActivity.kt

Quick Start

Add the component to your layout XML:
layout_activity.xml
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:
YourActivity.kt
Or in a Fragment:
YourFragment.kt

Filtering Users

Pass a UsersRequest.UsersRequestBuilder to setUsersRequestBuilder. Pass the builder instance — not the result of .build().

Filter Recipes

The component uses infinite scroll — the next page loads as the user scrolls to the bottom. Refer to UsersRequestBuilder for the full builder API.

Search Request Builder

Use setSearchRequestBuilder to customize the search list separately from the main list:

Actions and Events

Callback Methods

setOnItemClick

Fires when a user row is tapped. Primary navigation hook — set the active user and render the message view.
YourActivity.kt
What this does: Replaces the default item-click behavior. When a user taps a user item, your custom lambda executes instead of the built-in navigation.

setOnItemLongClick

Fires when a user row is long-pressed. Use for additional actions like block or mute.
YourActivity.kt

setOnBackPressListener

Fires when the user presses the back button in the app bar. Default: navigates to the previous activity.
YourActivity.kt

setOnSelect

Fires when a user is checked/unchecked in multi-select mode. Requires setSelectionMode to be set.
YourActivity.kt

setOnError

Fires on internal errors (network failure, auth issue, SDK exception).
YourActivity.kt

setOnLoad

Fires when the list is successfully fetched and loaded.
YourActivity.kt

setOnEmpty

Fires when the list is empty, enabling custom handling such as showing a placeholder.
YourActivity.kt
  • Verify: After setting an action callback, trigger the corresponding user interaction (tap, long-press, back, select) and confirm your custom logic executes instead of the default behavior.

Global UI Events

CometChatUserEvents emits events subscribable from anywhere in the application. Add a listener and remove it when no longer needed.
Add Listener
Remove Listener

SDK Events (Real-Time, Automatic)

The component listens to these SDK events internally. No manual attachment needed unless additional side effects are required.
Automatic: user presence changes update the status indicator in real time.

Functionality

Small functional customizations such as toggling visibility of UI elements and configuring selection modes.
  • Verify: After calling a visibility method, confirm the corresponding UI element is shown or hidden.

Custom View Slots

Each slot replaces a section of the default UI. Slots that accept a User parameter receive the user object for that row via the UsersViewHolderListener pattern (createView + bindView).

setLeadingView

Replace the avatar / left section.
What this does: Registers a UsersViewHolderListener that provides a custom view for the leading (left) area of each user item. createView inflates your layout, and bindView populates it with user data.

setTitleView

Replace the name / title text.
Inline role badge example:
Create a custom_user_title_view.xml layout:
custom_user_title_view.xml

setSubtitleView

Replace the subtitle text below the user’s name.
Example with last-active timestamp:

setTrailingView

Replace the right section of each user item.
Role tag badge example:
Create a custom_user_tail_view.xml layout:
custom_user_tail_view.xml

setItemView

Replace the entire list item row.
The Java method name is seItemView (note the missing ‘t’). This is a known typo in the SDK. In Kotlin, property access syntax normalizes this.
Example with online status background:
Create a custom_list_item_view.xml layout:
custom_list_item_view.xml

setOptions

Replace the long-press context menu entirely.

addOptions

Append to the long-press context menu without removing defaults.

setLoadingView

Sets a custom loading view displayed when data is being fetched.

setEmptyView

Configures a custom view displayed when there are no users in the list.

setErrorView

Defines a custom error state view that appears when an issue occurs while loading users.

setOverflowMenu

Replace the toolbar overflow menu.
  • Verify: After setting any custom view slot, confirm the custom view renders in the correct position within the user list item, and the data binding populates correctly for each user.

Common Patterns

Hide all chrome — minimal list

Friends-only list

Online users only

Advanced Methods

Programmatic Selection

selectUser

Programmatically selects or deselects a user. Works with both SINGLE and MULTIPLE selection modes.
In SINGLE mode, selecting a new user replaces the previous selection. In MULTIPLE mode, calling this on an already-selected user deselects it (toggle behavior).

clearSelection

Clears all selected users and resets the selection UI.

getSelectedUsers

Returns the list of currently selected User objects.

Selected Users List

When using multi-select mode, a horizontal list of selected users can be shown above the main list.

Search Input Customization

The built-in search box can be customized programmatically:

Internal Access

These methods provide direct access to internal components for advanced use cases.
Use these only when the standard API is insufficient. Directly manipulating the adapter or ViewModel may conflict with the component’s internal state management.

Style

The component uses XML theme styles. Define a custom style with parent CometChatUsersStyle in themes.xml, then apply with setStyle().
themes.xml
To know more such attributes, visit the attributes file.

Programmatic Style Properties

In addition to XML theme styles, the component exposes programmatic setters for fine-grained control:

Checkbox Style Properties (Selection Mode)

When using SINGLE or MULTIPLE selection mode, checkboxes appear on each item:

Customization Matrix

Next Steps

Conversations

Browse recent conversations

Groups

Browse and search available groups

Message List

Display messages in a conversation

Theming

Customize colors, fonts, and styles