Skip to main content
CometChatUsers renders a scrollable list of all available users with real-time presence updates, search, avatars, and online/offline status indicators.

Where It Fits

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

Quick Start

Add to your layout XML:
Or programmatically:
Prerequisites: CometChat SDK initialized with CometChatUIKit.init(), a user logged in, and the UI Kit dependency added. Or in a Fragment:

Filtering Users

Pass a UsersRequest.UsersRequestBuilder to control what loads:

Filter Recipes

RecipeBuilder method
Friends only.friendsOnly(true)
Limit per page.setLimit(10)
Search by keyword.setSearchKeyword("john")
Hide blocked users.hideBlockedUsers(true)
Filter by roles.setRoles(listOf("admin", "moderator"))
Filter by tags.setTags(listOf("vip"))
Online users only.setUserStatus(CometChatConstants.USER_STATUS_ONLINE)
Filter by UIDs.setUIDs(listOf("uid1", "uid2"))
Pass the builder object, not the result of .build(). The component calls .build() internally. Default page size is 30 with infinite scroll.

Actions and Events

Callback Methods

onItemClick

Fires when a user row is tapped. Primary navigation hook.
Replaces the default item-click behavior. Your custom lambda executes instead of the built-in navigation.

onItemLongClick

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

onBackPress

Fires when the user presses the back button in the toolbar.

onSearchClick

Fires when the user taps the search icon in the toolbar.

onSelection

Fires when users are selected/deselected in multi-select mode.

onError

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

onLoad

Fires when the list is successfully fetched and loaded.

onEmpty

Fires when the list is empty after loading.

SDK Events (Real-Time, Automatic)

The component listens to these SDK events internally. No manual setup needed.
SDK ListenerInternal behavior
onUserOnlineUpdates online status indicator for the user
onUserOfflineUpdates offline status indicator for the user

Functionality

Method (Kotlin XML)Compose ParameterDescription
setBackIconVisibility(View.VISIBLE)hideBackIcon = falseToggle back button
setToolbarVisibility(View.GONE)hideToolbar = trueToggle toolbar
setSearchBoxVisibility(View.GONE)hideSearchBox = trueToggle search box
setStickyHeaderVisibility(View.GONE)hideStickyHeader = trueToggle alphabetical sticky header
setUserStatusVisibility(View.GONE)hideUserStatus = trueToggle online status indicator
setSeparatorVisibility(View.GONE)hideSeparator = trueToggle list separators
setSelectionMode(MULTIPLE)selectionMode = MULTIPLEEnable selection mode
setTitle("Contacts")title = "Contacts"Custom toolbar title
setSearchPlaceholderText("Find...")searchPlaceholderText = "Find..."Search placeholder

Custom View Slots

Leading View

Replace the avatar / left section.

Title View

Replace the name / title text.

Subtitle View

Replace the subtitle text below the user’s name.

Trailing View

Replace the right section of each user item.

Item View

Replace the entire list item row.

State Views

Overflow Menu



Common Patterns

Minimal list — hide all chrome

Friends-only list

Online users only


Advanced Methods

Programmatic Selection

ViewModel Access

See ViewModel & Data for ListOperations, state observation, and custom repositories.

Style

Define a custom style in themes.xml:
themes.xml

Style Properties

PropertyDescription
backgroundColorList background color
titleTextColorToolbar title color
searchBoxStyleSearch box appearance
itemStyle.backgroundColorRow background
itemStyle.selectedBackgroundColorSelected row background
itemStyle.titleTextColorUser name color
itemStyle.subtitleTextColorSubtitle text color
itemStyle.separatorColorRow separator color
itemStyle.avatarStyleAvatar appearance
itemStyle.statusIndicatorStyleOnline/offline indicator
See Component Styling for the full reference.

Next Steps

Conversations

Browse recent conversations

Groups

Browse and search available groups

Component Styling

Detailed styling reference with screenshots

ViewModel & Data

Custom ViewModels, repositories, and ListOperations