Skip to main content

Overview

CometChatGroups functions as a standalone component designed to create a screen displaying a list of groups, with the added functionality of enabling groups to search for specific groups. Acting as a container component, CometChatGroups encapsulates and formats the CometChatListBase and CometChatGroupList components without introducing any additional behavior of its own.

Usage


Integration

The following code snippet illustrates how you can can launch CometChatGroups.

Actions

Actions dictate how a component functions. They are divided into two types: Predefined and Group-defined. You can override either type, allowing you to tailor the behavior of the component to fit your specific needs.
setOnItemClick
Function invoked when a Group item is clicked, typically used to open a Group profile or chat screen.
YourActivity.java

setOnItemLongClick
Function executed when a Group item is long-pressed, allowing additional actions like delete or block.
YourActivity.java

setOnBackPressListener
OnBackPressListener is triggered when you press the back button in the app bar. It has a predefined behavior; when clicked, it navigates to the previous activity. However, you can override this action using the following code snippet.
YourActivity.java

setOnSelect
Called when a item from the fetched list is selected, useful for multi-selection features.
YourActivity.java

OnError
This action doesn’t change the behavior of the component but rather listens for any errors that occur in the groups component.
YourActivity.java

setOnLoad
Invoked when the list is successfully fetched and loaded, helping track component readiness.
YourActivity.java

setOnEmpty
Called when the list is empty, enabling custom handling such as showing a placeholder message.
YourActivity.java

Filters

Filters allow you to customize the data displayed in a list within a Component. You can filter the list based on your specific criteria, allowing for a more customized. Filters can be applied using RequestBuilders of Chat SDK.
1. GroupsRequestBuilder
The GroupsRequestBuilder enables you to filter and customize the group list based on available parameters in GroupsRequestBuilder. This feature allows you to create more specific and targeted queries when fetching groups. The following are the parameters available in GroupsRequestBuilder Example In the example below, we are applying a filter to the Group List based on only joined groups.

2. SearchRequestBuilder
The SearchRequestBuilder uses GroupsRequestBuilder enables you to filter and customize the search list based on available parameters in GroupsRequestBuilder. This feature allows you to keep uniformity between the displayed Groups List and searched Group List. Example

Events

Events are emitted by a Component. By using event you can extend existing functionality. Being global events, they can be applied in Multiple Locations and are capable of being Added or Removed. The list of events emitted by the Groups component is as follows.
1. Add CometChatGroupEvents Listener’s

2. Removing CometChatGroupEvents Listener’s

Customization

To fit your app’s design requirements, you can customize the appearance of the groups component. We provide exposed methods that allow you to modify the experience and behavior according to your specific needs.

Style

Using Style you can customize the look and feel of the component in your app, These parameters typically control elements such as the color, size, shape, and fonts used within the component.

To know more such attributes, visit the attributes file.

Functionality

These are a set of small functional customizations that allow you to fine-tune the overall experience of the component. With these, you can change text, set custom icons, and toggle the visibility of UI elements. Below is a list of customizations along with corresponding code snippets

Advanced

For advanced-level customization, you can set custom views to the component. This lets you tailor each aspect of the component to fit your exact needs and application aesthetics. You can create and define your views, layouts, and UI elements and then incorporate those into the component.

setOptions

Defines the available actions when users interact with a group item, such as long-pressing or swiping. Use Cases:
  • Enable actions like “Mute Notifications”, “Leave Group”, “Pin Group”.
  • Provide admin-only actions like “Manage Members”, “Delete Group”.

addOptions

This method extends the existing set of actions available when Groups long press a Group item. Unlike setOptionsDefines, which replaces the default options, addOptionsAdds allows developers to append additional actions without removing the default ones. Example use cases include:
  • Adding a “Report Spam” action
  • Introducing a “Save to Notes” option
  • Integrating third-party actions such as “Share to Cloud Storage”
This method provides flexibility in modifying Group interaction capabilities.

setLoadingView

Configures a custom loading view displayed while groups are being fetched. Use Cases:
  • Show a spinner with “Loading groups…” text.
  • Display a skeleton loader for a smooth UI experience.

setEmptyView

Defines a view that appears when no groups are available. Use Cases:
  • Show a message like “No groups found, create one now!”.
  • Display an illustration with a “Create New Group” button.

setErrorView

Configures the UI when an error occurs while fetching groups. Use Cases:
  • Display a retry button with “Failed to load groups, try again.”.
  • Show a friendly error illustration.

setLeadingView

Sets a custom leading view that appears at the start of each group item. Use Cases:
  • Display the group profile picture.
  • Add an icon indicating Public or Private groups.
You can indeed create a custom layout file named custom_leading_avatar_view.xml for more complex or unique list items. Once this layout file is made, you would inflate it inside the createView() method of the GroupsViewHolderListener. The inflation process prepares the layout for use in your application: Following this, you would use the bindView() method to initialize and assign values to your individual views. This could include setting text on TextViews, images on ImageViews, and so on based on the properties of the Group object:
custom_leading_avatar_view.xml

setTitleView

Customizes the title view of each group item, which typically displays the group name. Use Cases:
  • Style group names with custom fonts and colors.
  • Show a verified badge for official groups.
You can indeed create a custom layout file named custom_title_view.xml for more complex or unique list items. Once this layout file is made, you would inflate it inside the createView() method of the GroupsViewHolderListener. The inflation process prepares the layout for use in your application: Following this, you would use the bindView() method to initialize and assign values to your individual views. This could include setting text on TextViews, images on ImageViews, and so on based on the properties of the Group object:
custom_title_view.xml

setTrailingView

Allows custom elements to be added at the end of each group item, such as buttons or indicators. Use Cases:
  • Show unread message counts.
  • Add a quick Join or Leave button.
You can indeed create a custom layout file named custom_tail_view.xml for more complex or unique list items. Once this layout file is made, you would inflate it inside the createView() method of the GroupsViewHolderListener. The inflation process prepares the layout for use in your application: Following this, you would use the bindView() method to initialize and assign values to your individual views. This could include setting text on TextViews, images on ImageViews, and so on based on the properties of the Group object:
custom_tail_view.xml

setItemView

Assigns a fully custom ListItem layout to the Groups component, replacing the default design. Use Cases:
  • Add a description below the group name.
  • Customize layout to include additional metadata.
Example
You can indeed create a custom layout file named item_list.xml for more complex or unique list items. Once this layout file is made, you would inflate it inside the createView() method of the GroupsViewHolderListener. The inflation process prepares the layout for use in your application: Following this, you would use the bindView() method to initialize and assign values to your individual views. This could include setting text on TextViews, images on ImageViews, and so on based on the properties of the Group object:
custom_group_list_itemd.xml
YourActivity.java

setSubTitleView

Customizes the subtitle view for each group item, which typically displays extra information. Use Cases:
  • Show last message preview.
  • Display the number of members.
Example
You can indeed create a custom layout file named subtitle_layout.xml for more complex or unique list items. Once this layout file is made, you would inflate it inside the createView() method of the GroupsViewHolderListener. The inflation process prepares the layout for use in your application: Following this, you would use the bindView() method to initialize and assign values to your individual views. This could include setting text on TextViews, images on ImageViews, and so on based on the properties of the Group object:
YourActivity.java

SetOverflowMenu

Customizes the overflow menu (three-dot ⋮ icon) with additional options. Use Cases:
  • Add options like “Invite Members”, “Report Group”.
  • Enable admin-specific options like “Manage Group Settings”.
Example
You need to create a overflow_menu_layout.xml as a custom view file. Which we will inflate and pass to .setOverflowMenu().
overflow_menu_layout.xml
You inflate the view and pass it to setOverflowMenu. You can get the child view reference and can handle click actions.
YourActivity.java