AI Agent Component Spec
AI Agent Component Spec
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.
- Kotlin
- Java
ChatActivity.kt
Quick Start
Add the component to your layout XML:layout_activity.xml

CometChatUIKit.init(), a user logged in, and the cometchat-chat-uikit-android dependency added.
To add programmatically in an Activity:
- Kotlin
- Java
YourActivity.kt
- Kotlin
- Java
YourFragment.kt
Filtering Groups
Pass aGroupsRequest.GroupsRequestBuilder to setGroupsRequestBuilder. Pass the builder instance — not the result of .build().
- Kotlin
- Java
Filter Recipes
| Recipe | Code |
|---|---|
| Joined only | builder.joinedOnly(true) |
| Limit to 10 per page | builder.setLimit(10) |
| Search by keyword | builder.setSearchKeyWord("design") |
| Filter by tags | builder.setTags(Arrays.asList("vip")) |
| With tags | builder.withTags(true) |
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
UsesetSearchRequestBuilder to customize the search list separately from the main list:
- Kotlin
- Java
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.
- Kotlin
- Java
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.
- Kotlin
- Java
YourActivity.kt
setOnBackPressListener
Fires when the user presses the back button in the app bar. Default: navigates to the previous activity.
- Kotlin
- Java
YourActivity.kt
setOnSelection
Fires when a group is checked/unchecked in multi-select mode. Requires setSelectionMode to be set.
- Kotlin
- Java
YourActivity.kt
setOnError
Fires on internal errors (network failure, auth issue, SDK exception).
- Kotlin
- Java
YourActivity.kt
setOnLoad
Fires when the list is successfully fetched and loaded.
- Kotlin
- Java
YourActivity.kt
setOnEmpty
Fires when the list is empty, enabling custom handling such as showing a placeholder.
- Kotlin
- Java
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.
| Event | Fires when | Payload |
|---|---|---|
ccGroupCreated | The logged-in user creates a group | Group |
ccGroupDeleted | The logged-in user deletes a group | Group |
ccGroupLeft | The logged-in user leaves a group | Action, User, Group |
ccGroupMemberJoined | The logged-in user joins a group | User, Group |
ccGroupMemberAdded | The logged-in user adds members to a group | List<Action>, List<User>, Group, User |
ccGroupMemberKicked | The logged-in user kicks a member | Action, User, User, Group |
ccGroupMemberBanned | The logged-in user bans a member | Action, User, User, Group |
ccGroupMemberUnBanned | The logged-in user unbans a member | Action, User, User, Group |
ccGroupMemberScopeChanged | The logged-in user changes a member’s scope | Action, User, String, String, Group |
ccOwnershipChanged | The logged-in user transfers group ownership | Group, GroupMember |
- Kotlin
- Java
Add Listener
SDK Events (Real-Time, Automatic)
The component listens to these SDK events internally. No manual attachment needed unless additional side effects are required.| SDK Listener | Internal behavior |
|---|---|
onGroupMemberJoined | Updates the group list when a member joins |
onGroupMemberLeft | Updates the group list when a member leaves |
onGroupMemberKicked | Updates the group list when a member is kicked |
onGroupMemberBanned | Updates the group list when a member is banned |
onGroupMemberUnbanned | Updates the group list when a member is unbanned |
onGroupMemberScopeChanged | Updates the group list when a member’s scope changes |
onMemberAddedToGroup | Updates the group list when members are added |
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.| Methods | Description | Code |
|---|---|---|
setBackIconVisibility | Toggles visibility for the back button in the app bar | .setBackIconVisibility(View.VISIBLE); |
setToolbarVisibility | Toggles visibility for the toolbar in the app bar | .setToolbarVisibility(View.GONE); |
setLoadingStateVisibility | Hides the loading state while fetching groups | .setLoadingStateVisibility(View.GONE); |
setErrorStateVisibility | Hides the error state on fetching groups | .setErrorStateVisibility(View.GONE); |
setEmptyStateVisibility | Hides the empty state on fetching groups | .setEmptyStateVisibility(View.GONE); |
setSeparatorVisibility | Controls visibility of separators in the list view | .setSeparatorVisibility(View.GONE); |
setGroupTypeVisibility | Controls visibility of the group type indicator (public, private, password) | .setGroupTypeVisibility(View.GONE); |
setSearchBoxVisibility | Controls visibility of the search box in the toolbar | .setSearchBoxVisibility(View.GONE); |
setSelectionMode | Determines the selection mode (single or multiple) | .setSelectionMode(UIKitConstants.SelectionMode.MULTIPLE); |
setSearchKeyword | Programmatically triggers a search with the given keyword | .setSearchKeyword("design"); |
setTitleText | Sets a custom title in the toolbar | .setTitleText("My Groups"); |
setTitleVisibility | Toggles visibility for the title text in the toolbar | .setTitleVisibility(View.GONE); |
setSearchPlaceholderText | Sets the placeholder text for the search input | .setSearchPlaceholderText("Find groups..."); |
- 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 aGroup parameter receive the group object for that row via the GroupsViewHolderListener pattern (createView + bindView).
| Slot | Method | Replaces |
|---|---|---|
| Leading view | setLeadingView(GroupsViewHolderListener) | Avatar / left section |
| Title view | setTitleView(GroupsViewHolderListener) | Name / title text |
| Subtitle view | setSubtitleView(GroupsViewHolderListener) | Subtitle text below name |
| Trailing view | setTrailingView(GroupsViewHolderListener) | Right section |
| Item view | setItemView(GroupsViewHolderListener) | Entire list item row |
| Loading view | setLoadingView(@LayoutRes int) | Loading spinner |
| Empty view | setEmptyView(@LayoutRes int) | Empty state |
| Error view | setErrorView(@LayoutRes int) | Error state |
| Overflow menu | setOverflowMenu(View) | Toolbar menu |
| Options (replace) | setOptions(Function2) | Long-press context menu (replaces defaults) |
| Options (append) | addOptions(Function2) | Long-press context menu (appends to defaults) |
setLeadingView
Replace the avatar / left section.
- Kotlin
- Java
What this does: Registers aJoin status badge example:GroupsViewHolderListenerthat provides a custom view for the leading (left) area of each group item.createViewinflates your layout, andbindViewpopulates it with group data.

custom_leading_avatar_view.xml layout:
custom_leading_avatar_view.xml
- Kotlin
- Java
setTitleView
Replace the name / title text.
- Kotlin
- Java

custom_group_title_view.xml layout:
custom_group_title_view.xml
- Kotlin
- Java
setSubtitleView
Replace the subtitle text below the group’s name.
- Kotlin
- Java

- Kotlin
- Java
YourActivity.kt
setTrailingView
Replace the right section of each group item.
- Kotlin
- Java

custom_tail_view.xml layout:
custom_tail_view.xml
- Kotlin
- Java
setItemView
Replace the entire list item row.
- Kotlin
- Java

custom_group_list_item.xml layout:
custom_group_list_item.xml
- Kotlin
- Java
YourActivity.kt
setOptions
Replace the long-press context menu entirely.
- Kotlin
- Java
addOptions
Append to the long-press context menu without removing defaults.
- Kotlin
- Java
setLoadingView
Sets a custom loading view displayed when data is being fetched.
- Kotlin
- Java
setEmptyView
Configures a custom view displayed when there are no groups in the list.
- Kotlin
- Java
setErrorView
Defines a custom error state view that appears when an issue occurs while loading groups.
- Kotlin
- Java
setOverflowMenu
Replace the toolbar overflow menu.

overflow_menu_layout.xml layout:
overflow_menu_layout.xml
- Kotlin
- Java
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
- Kotlin
- Java
Joined groups only
- Kotlin
- Java
Filter by tags
- Kotlin
- Java
Advanced Methods
Programmatic Selection
selectGroup
Programmatically selects or deselects a group. Works with both SINGLE and MULTIPLE selection modes.
- Kotlin
- Java
InSINGLEmode, selecting a new group replaces the previous selection. InMULTIPLEmode, calling this on an already-selected group deselects it (toggle behavior).
clearSelection
Clears all selected groups and resets the selection UI.
- Kotlin
- Java
getSelectedGroups
Returns the list of currently selected Group objects.
- Kotlin
- Java
Selected Groups List
When using multi-select mode, a horizontal list of selected groups can be shown above the main list.| Method | Type | Description |
|---|---|---|
setSelectedGroupsListVisibility | int (View.VISIBLE / View.GONE) | Show or hide the selected groups strip |
setSelectedGroupAvatarStyle | @StyleRes int | Avatar style for selected group chips |
setSelectedGroupItemTextColor | @ColorInt int | Text color for selected group names |
setSelectedGroupItemTextAppearance | @StyleRes int | Text appearance for selected group names |
setSelectedGroupItemRemoveIcon | Drawable | Icon for the remove button on each chip |
setSelectedGroupItemRemoveIconTint | @ColorInt int | Tint color for the remove icon |
Search Input Customization
The built-in search box can be customized programmatically:| Method | Type | Description |
|---|---|---|
setSearchPlaceholderText | String | Sets the placeholder text for the search input |
setSearchInputTextColor | @ColorInt int | Text color of the search input |
setSearchInputTextAppearance | @StyleRes int | Text appearance of the search input |
setSearchInputPlaceHolderTextColor | @ColorInt int | Placeholder text color |
setSearchInputPlaceHolderTextAppearance | @StyleRes int | Placeholder text appearance |
setSearchInputIcon | Drawable | Leading icon in the search box |
setSearchInputIconTint | @ColorInt int | Tint for the leading icon |
setSearchInputEndIcon | Drawable | Trailing icon in the search box |
setSearchInputEndIconTint | @ColorInt int | Tint for the trailing icon |
setSearchInputStrokeWidth | @Dimension int | Stroke width of the search box border |
setSearchInputStrokeColor | @ColorInt int | Stroke color of the search box border |
setSearchInputBackgroundColor | @ColorInt int | Background color of the search box |
setSearchInputCornerRadius | @Dimension int | Corner radius of the search box |
Internal Access
These methods provide direct access to internal components for advanced use cases.| Method | Returns | Description |
|---|---|---|
getBinding() | CometchatGroupListBinding | The ViewBinding for the component’s root layout |
getViewModel() | GroupsViewModel | The ViewModel managing group data and state |
getAdapter() | GroupsAdapter | The adapter powering the RecyclerView |
setAdapter(GroupsAdapter) | void | Replaces the default adapter with a custom one |
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 parentCometChatGroupsStyle in themes.xml, then apply with setStyle().

themes.xml
- Kotlin
- Java
Programmatic Style Properties
In addition to XML theme styles, the component exposes programmatic setters for fine-grained control:| Method | Type | Description |
|---|---|---|
setBackgroundColor | @ColorInt int | Background color of the component |
setBackIconTint | @ColorInt int | Tint color for the back icon |
setBackIcon | Drawable | Custom back icon drawable |
setTitleTextColor | @ColorInt int | Title text color in the toolbar |
setTitleTextAppearance | @StyleRes int | Title text appearance in the toolbar |
setItemTitleTextColor | @ColorInt int | Text color for group item titles |
setItemTitleTextAppearance | @StyleRes int | Text appearance for group item titles |
setItemBackgroundColor | @ColorInt int | Background color for list items |
setItemSelectedBackgroundColor | @ColorInt int | Background color for selected list items |
setSeparatorColor | @ColorInt int | Color of list item separators |
setStrokeColor | @ColorInt int | Stroke color of the component border |
setStrokeWidth | @Dimension int | Stroke width of the component border |
setCornerRadius | @Dimension int | Corner radius of the component |
setSubtitleTextColor | @ColorInt int | Text color for group item subtitles |
setSubtitleTextAppearance | @StyleRes int | Text appearance for group item subtitles |
setEmptyStateTextColor | @ColorInt int | Title text color for the empty state |
setEmptyStateTextAppearance | @StyleRes int | Title text appearance for the empty state |
setEmptyStateSubtitleTextColor | @ColorInt int | Subtitle text color for the empty state |
setEmptyStateSubTitleTextAppearance | @StyleRes int | Subtitle text appearance for the empty state |
setErrorStateTextColor | @ColorInt int | Title text color for the error state |
setErrorStateTextAppearance | @StyleRes int | Title text appearance for the error state |
setErrorStateSubtitleColor | @ColorInt int | Subtitle text color for the error state |
setErrorStateSubtitleTextAppearance | @StyleRes int | Subtitle text appearance for the error state |
setRetryButtonTextColor | @ColorInt int | Text color for the retry button |
setRetryButtonTextAppearance | @StyleRes int | Text appearance for the retry button |
setRetryButtonBackgroundColor | @ColorInt int | Background color for the retry button |
setRetryButtonStrokeColor | @ColorInt int | Stroke color for the retry button |
setRetryButtonStrokeWidth | @Dimension int | Stroke width for the retry button |
setRetryButtonCornerRadius | @Dimension int | Corner radius for the retry button |
setAvatarStyle | @StyleRes int | Style for group avatars |
setStatusIndicatorStyle | @StyleRes int | Style for group type status indicators |
Checkbox Style Properties (Selection Mode)
When usingSINGLE or MULTIPLE selection mode, checkboxes appear on each item:
| Method | Type | Description |
|---|---|---|
setCheckBoxStrokeWidth | @Dimension int | Stroke width of the checkbox border |
setCheckBoxCornerRadius | @Dimension int | Corner radius of the checkbox |
setCheckBoxStrokeColor | @ColorInt int | Stroke color of the checkbox border |
setCheckBoxBackgroundColor | @ColorInt int | Background color of unchecked checkbox |
setCheckBoxCheckedBackgroundColor | @ColorInt int | Background color of checked checkbox |
setCheckBoxSelectIcon | Drawable | Icon shown when checkbox is checked |
setCheckBoxSelectIconTint | @ColorInt int | Tint for the checkbox select icon |
setDiscardSelectionIcon | Drawable | Icon for the discard selection button |
setDiscardSelectionIconTint | @ColorInt int | Tint for the discard selection icon |
setSubmitSelectionIcon | Drawable | Icon for the submit selection button |
setSubmitSelectionIconTint | @ColorInt int | Tint for the submit selection icon |
Customization Matrix
| What to change | Where | Property/API | Example |
|---|---|---|---|
| Override behavior on group interaction | Activity/Fragment | setOn<Event> callbacks | setOnItemClick((v, pos, g) -> { ... }) |
| Filter which groups appear | Activity/Fragment | setGroupsRequestBuilder | setGroupsRequestBuilder(builder) |
| Customize search results | Activity/Fragment | setSearchRequestBuilder | setSearchRequestBuilder(builder) |
| Toggle visibility of UI elements | Activity/Fragment | set<Feature>Visibility(int) | setGroupTypeVisibility(View.GONE) |
| Replace a section of the list item | Activity/Fragment | set<Slot>View | setLeadingView(listener) |
| Change colors, fonts, spacing | themes.xml | CometChatGroupsStyle | <item name="cometchatGroupsSeparatorColor">#F76808</item> |
| Avatar style (corner radius, background) | themes.xml | cometchatGroupsAvatar | <item name="cometchatAvatarStrokeRadius">8dp</item> |
| Apply a custom style | Activity/Fragment | setStyle(int styleRes) | cometchatGroups.setStyle(R.style.CustomGroupsStyle); |
| Back button visibility | Activity/Fragment | setBackIconVisibility(int) | .setBackIconVisibility(View.VISIBLE); |
| Toolbar visibility | Activity/Fragment | setToolbarVisibility(int) | .setToolbarVisibility(View.GONE); |
| Error state visibility | Activity/Fragment | setErrorStateVisibility(int) | .setErrorStateVisibility(View.GONE); |
| Empty state visibility | Activity/Fragment | setEmptyStateVisibility(int) | .setEmptyStateVisibility(View.GONE); |
| Loading state visibility | Activity/Fragment | setLoadingStateVisibility(int) | .setLoadingStateVisibility(View.GONE); |
| Separator visibility | Activity/Fragment | setSeparatorVisibility(int) | .setSeparatorVisibility(View.GONE); |
| Group type indicator visibility | Activity/Fragment | setGroupTypeVisibility(int) | .setGroupTypeVisibility(View.GONE); |
| Selection mode (single/multiple) | Activity/Fragment | setSelectionMode(SelectionMode) | .setSelectionMode(UIKitConstants.SelectionMode.MULTIPLE); |
| Search keyword | Activity/Fragment | setSearchKeyword(String) | .setSearchKeyword("design"); |
| Search box visibility | Activity/Fragment | setSearchBoxVisibility(int) | .setSearchBoxVisibility(View.GONE); |
| Custom toolbar title | Activity/Fragment | setTitleText(String) | .setTitleText("My Groups"); |
| Title visibility | Activity/Fragment | setTitleVisibility(int) | .setTitleVisibility(View.GONE); |
| Search placeholder | Activity/Fragment | setSearchPlaceholderText(String) | .setSearchPlaceholderText("Find groups..."); |
| Long-press options (replace) | Activity/Fragment | setOptions(Function2) | See setOptions code above |
| Long-press options (append) | Activity/Fragment | addOptions(Function2) | See addOptions code above |
| Loading view | Activity/Fragment | setLoadingView(int) | .setLoadingView(R.layout.your_loading_view); |
| Empty view | Activity/Fragment | setEmptyView(int) | .setEmptyView(R.layout.your_empty_view); |
| Error view | Activity/Fragment | setErrorView(int) | .setErrorView(R.layout.your_error_view); |
| Leading view (avatar area) | Activity/Fragment | setLeadingView(GroupsViewHolderListener) | See setLeadingView code above |
| Title view | Activity/Fragment | setTitleView(GroupsViewHolderListener) | See setTitleView code above |
| Trailing view | Activity/Fragment | setTrailingView(GroupsViewHolderListener) | See setTrailingView code above |
| Entire list item | Activity/Fragment | setItemView(GroupsViewHolderListener) | See setItemView code above |
| Subtitle view | Activity/Fragment | setSubtitleView(GroupsViewHolderListener) | See setSubtitleView code above |
| Overflow menu | Activity/Fragment | setOverflowMenu(View) | cometchatGroups.setOverflowMenu(view); |
| Programmatic selection | Activity/Fragment | selectGroup(Group, SelectionMode) | .selectGroup(group, SelectionMode.SINGLE); |
| Clear selection | Activity/Fragment | clearSelection() | .clearSelection(); |
| Selected groups strip | Activity/Fragment | setSelectedGroupsListVisibility(int) | .setSelectedGroupsListVisibility(View.VISIBLE); |
| Internal adapter access | Activity/Fragment | getAdapter() / setAdapter() | Advanced use only |
Accessibility
The component renders a scrollableRecyclerView of interactive group items. Each group row responds to tap and long-press gestures. Avatar images include the group name as content description. Group type indicators (public, private, password-protected) provide visual differentiation.
For custom views provided via setLeadingView, setTitleView, setTrailingView, or setItemView, ensure you set android:contentDescription on visual-only elements so TalkBack can announce them. The default views handle this automatically.
Group type status dots are visual-only by default. If screen reader descriptions are needed, provide them via a custom view with appropriate contentDescription attributes.