Skip to main content

Where It Fits

CometChatGroupMembers is a list component. It renders all members of a specific group and emits the selected GroupMember via setOnItemClick. It requires a Group object set via setGroup() before it can load data. Wire it to CometChatMessageHeader, CometChatMessageList, and CometChatMessageComposer to build a group messaging layout.
GroupChatActivity.kt

Quick Start

Add the component to your layout XML:
layout_activity.xml
Prerequisites: CometChat SDK initialized with CometChatUIKit.init(), a user logged in, the cometchat-chat-uikit-android dependency added, and a valid Group object with a group ID (GUID). Set the Group object in your Activity or Fragment:
YourActivity.kt
What this does: Creates a Group object with a group ID and name, then passes it to the CometChatGroupMembers component. The component fetches and displays all members of that group.
Or add programmatically in an Activity:
YourActivity.kt
Or in a Fragment:
YourFragment.kt

Filtering Group Members

Pass a GroupMembersRequest.GroupMembersRequestBuilder to setGroupMembersRequestBuilder. 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.

Search Request Builder

Use setSearchRequestBuilder to customize the search list separately from the main list:
What this does: Creates a GroupMembersRequestBuilder with a group ID, limit, and search keyword, then applies it as the search request builder. When the user searches, the component uses this builder to filter results.

Actions and Events

Callback Methods

setOnItemClick

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

setOnItemLongClick

Fires when a group member row is long-pressed. Use for additional actions like kick, ban, or change scope.
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 member 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

setOnLoadMore

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
What this does: Registers a global event listener tagged with "LISTENER_TAG". When a group member is kicked, banned, or has their scope changed, the corresponding callback fires with the action details, affected user, and group information.

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 and user presence 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 GroupMember parameter receive the group member object for that row via the GroupMembersViewHolderListeners pattern (createView + bindView).

setLeadingView

Replace the avatar / left section.
What this does: Registers a GroupMembersViewHolderListeners that provides a custom view for the leading (left) area of each group member item. createView inflates your layout, and bindView populates it with group member data.
Scope badge avatar example:
Create a custom layout file named custom_title_view.xml:
custom_title_view.xml
What this does: Defines a custom leading view layout with a CometChatAvatar and a role badge view that can display different backgrounds based on the member’s scope (admin, moderator, participant).
YourActivity.kt
What this does: Inflates a custom leading view layout and populates it with the group member’s avatar and a role-based badge. If the member is an admin, the badge shows the marketing_head drawable; if a moderator, sr_manager; if a participant, content_manager; otherwise, team_member. The view is sized to 40dp × 40dp.

setTitleView

Replace the name / title text.
Inline role badge example:
Create a custom layout file named custom_title_view.xml:
custom_title_view.xml
What this does: Defines a custom title view layout with a TextView for the member name and a View for the role badge, arranged horizontally.
YourActivity.kt
What this does: Inflates a custom title view layout and populates it with the group member’s name and a role-based badge. The badge background changes based on the member’s scope: marketing_head for admin, sr_manager for moderator, content_manager for participant, and team_member for others.

setSubtitleView

Replace the subtitle text below the member’s name.
Example with join date:
YourActivity.kt
What this does: Creates a TextView as the subtitle view and populates it with the group member’s join date formatted as “dd/MM/yyyy, HH:mm:ss”. The joinedAt timestamp is multiplied by 1000 to convert from seconds to milliseconds.

setTrailingView

Replace the right section of each group member item.
Scope badge example:
Create a custom layout file named custom_tail_view.xml:
custom_tail_view.xml
What this does: Defines a custom trailing view layout with a MaterialCardView containing a TextView that displays the member’s scope as a colored badge.
YourActivity.kt
What this does: Inflates a custom trailing view that displays a scope badge for each group member. The badge background uses the extended primary color, the text shows the member’s scope, and the badge is only visible for participants (hidden for admins, moderators, and owners).

setItemView

Replace the entire list item row.
Example with name and scope:
Create a custom layout file named item_list.xml:
item_list.xml
What this does: Defines a custom list item layout with two TextView elements: one for the member name and one for the subtitle (scope), arranged vertically.
YourActivity.kt
What this does: Inflates a custom list item layout and populates it with the group member’s name and scope. Each list item shows the member name in the primary text style and their scope (admin, moderator, participant) in the secondary text style.

setOptions

Replace the long-press context menu entirely.

addOptions

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

setLoadingStateView

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

setEmptyStateView

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

setErrorStateView

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

setOverflowMenu

Replace the toolbar overflow menu.
What this does: Creates an ImageView with an add icon and sets it as the overflow menu in the group members toolbar. This provides a quick action button for adding new members.
  • Verify: After setting any custom view slot, confirm the custom view renders in the correct position within the group member list item, and the data binding populates correctly for each member.

Common Patterns

Hide all chrome — minimal list

Admins-only list

Exclude group owner

Hide kick/ban/scope options

Advanced Methods

Programmatic Selection

selectGroupMember

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

getSelectedGroupMembers

Returns the list of currently selected GroupMember objects.

Selected Group Members List

When using multi-select mode, a horizontal list of selected group members 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 CometChatGroupMembersStyle in themes.xml, then apply with setStyle().
themes.xml
What this does: Applies the CustomGroupMembersStyle theme to the CometChatGroupMembers component, changing the avatar, separator, title text, and back icon appearance.
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

Groups

Browse and search available groups

Users

Browse and search available users

Conversations

Browse recent conversations

Message List

Display messages in a conversation