Skip to main content

Where It Fits

CometChatGroups is a list component. It renders all available groups and emits the selected Group via setOnItemClick. Wire it to CometChatMessageHeader, CometChatMessageList, and CometChatMessageComposer to build a group 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 Groups

Pass a GroupsRequest.GroupsRequestBuilder to setGroupsRequestBuilder. 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 GroupsRequestBuilder 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 group row is tapped. Primary navigation hook — set the active group and render the message view.
YourActivity.kt
What this does: Replaces the default item-click behavior. When a user taps a group, your custom lambda executes instead of the built-in navigation.

setOnItemLongClick

Fires when a group row is long-pressed. Use for additional actions like delete or leave.
YourActivity.kt

setOnBackPressListener

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

setOnSelection

Fires when a group 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

CometChatGroupEvents 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: group membership changes update the list 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 Group parameter receive the group object for that row via the GroupsViewHolderListener pattern (createView + bindView).

setLeadingView

Replace the avatar / left section.
What this does: Registers a GroupsViewHolderListener that provides a custom view for the leading (left) area of each group item. createView inflates your layout, and bindView populates it with group data.
Join status badge example:
Create a custom_leading_avatar_view.xml layout:
custom_leading_avatar_view.xml

setTitleView

Replace the name / title text.
Group type icon example:
Create a custom_group_title_view.xml layout:
custom_group_title_view.xml

setSubtitleView

Replace the subtitle text below the group’s name.
Example with member count and description:
YourActivity.kt

setTrailingView

Replace the right section of each group item.
Join button example:
Create a custom_tail_view.xml layout:
custom_tail_view.xml

setItemView

Replace the entire list item row.
Custom list item example:
Create a custom_group_list_item.xml layout:
custom_group_list_item.xml
YourActivity.kt

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 groups in the list.

setErrorView

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

setOverflowMenu

Replace the toolbar overflow menu.
Create an overflow_menu_layout.xml layout:
overflow_menu_layout.xml
YourActivity.kt
  • Verify: After setting any custom view slot, confirm the custom view renders in the correct position within the group list item, and the data binding populates correctly for each group.

Common Patterns

Hide all chrome — minimal list

Joined groups only

Filter by tags

Advanced Methods

Programmatic Selection

selectGroup

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

clearSelection

Clears all selected groups and resets the selection UI.

getSelectedGroups

Returns the list of currently selected Group objects.

Selected Groups List

When using multi-select mode, a horizontal list of selected groups 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 CometChatGroupsStyle 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

Users

Browse and search available users

Group Members

View and manage group members

Message List

Display messages in a conversation