Skip to main content
{
  "component": "CometChatThreadHeader",
  "package": "com.cometchat.chatuikit.threadheader",
  "xmlElement": "<com.cometchat.chatuikit.threadheader.CometChatThreadHeader />",
  "description": "Displays the parent message bubble and reply count for a threaded conversation. Requires setParentMessage(BaseMessage) to render.",
  "primaryInput": {
    "method": "setParentMessage",
    "type": "BaseMessage",
    "note": "Must be called to display the parent message in the thread header"
  },
  "primaryOutput": {
    "description": "Renders the parent message bubble and reply count. No primary callback output."
  },
  "methods": {
    "data": {
      "setParentMessage": {
        "type": "BaseMessage",
        "note": "Sets the parent message for the thread header. Required."
      }
    },
    "visibility": {
      "setReactionVisibility": { "type": "int (View.VISIBLE | View.GONE)", "default": "View.VISIBLE" },
      "setAvatarVisibility": { "type": "int (View.VISIBLE | View.GONE)", "default": "View.VISIBLE" },
      "setReceiptsVisibility": { "type": "int (View.VISIBLE | View.GONE)", "default": "View.VISIBLE" },
      "setReplyCountVisibility": { "type": "int (View.VISIBLE | View.GONE)", "default": "View.VISIBLE" },
      "setReplyCountBarVisibility": { "type": "int (View.VISIBLE | View.GONE)", "default": "View.VISIBLE" }
    },
    "templates": {
      "setTemplates": {
        "type": "List<CometChatMessageTemplate>",
        "note": "Replaces the default list of message templates"
      },
      "addTemplate": {
        "type": "CometChatMessageTemplate",
        "note": "Adds a single template to the existing list"
      }
    },
    "advanced": {
      "setAlignment": "UIKitConstants.MessageListAlignment — STANDARD or LEFT_ALIGNED",
      "setMaxHeight": "@Dimension int — maximum height in pixels",
      "setTimeFormat": "SimpleDateFormat — custom time format for the parent message",
      "setTextFormatters": "List<CometChatTextFormatter> — custom text formatters",
      "setIncomingMessageBubbleStyle": "@StyleRes int — incoming bubble style",
      "setOutgoingMessageBubbleStyle": "@StyleRes int — outgoing bubble style",
      "getRecyclerView": "RecyclerView — internal RecyclerView",
      "getBinding": "CometchatThreadHeaderBinding — root ViewBinding",
      "getThreadedHeaderViewModel": "ThreadHeaderViewModel — internal ViewModel",
      "getAdapter": "MessageAdapter — internal adapter"
    },
    "style": {
      "setStyle": {
        "type": "@StyleRes int",
        "parent": "CometChatThreadHeaderStyle"
      }
    }
  },
  "events": [],
  "sdkListeners": []
}

Where It Fits

CometChatThreadHeader is a header component for threaded message views. It renders the parent message bubble and reply count. Wire it above a CometChatMessageList and CometChatMessageComposer to build a complete threaded conversation layout.
ThreadActivity.kt
class ThreadActivity : AppCompatActivity() {

    private lateinit var threadHeader: CometChatThreadHeader
    private lateinit var messageList: CometChatMessageList
    private lateinit var messageComposer: CometChatMessageComposer

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_thread)

        threadHeader = findViewById(R.id.thread_header)
        messageList = findViewById(R.id.message_list)
        messageComposer = findViewById(R.id.message_composer)

        // parentMessage is the BaseMessage that started the thread
        threadHeader.setParentMessage(parentMessage)
        messageList.setParentMessage(parentMessage)
        messageComposer.setParentMessage(parentMessage)
    }
}

Quick Start

Add the component to your layout XML:
layout_activity.xml
<com.cometchat.chatuikit.threadheader.CometChatThreadHeader
    android:id="@+id/thread_header"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
Prerequisites: CometChat SDK initialized with CometChatUIKit.init(), a user logged in, and the cometchat-chat-uikit-android dependency added. Set the parent message in your Activity:
YourActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_thread)

    val threadHeader = findViewById<CometChatThreadHeader>(R.id.thread_header)
    threadHeader.setParentMessage(baseMessage)
}
Or in a Fragment:
YourFragment.kt
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
    val view = inflater.inflate(R.layout.fragment_thread, container, false)
    val threadHeader = view.findViewById<CometChatThreadHeader>(R.id.thread_header)
    threadHeader.setParentMessage(baseMessage)
    return view
}

Actions and Events

Callback Methods

CometChatThreadHeader does not expose component-specific callback methods like setOnItemClick or setOnError. It is a display-only header that renders the parent message and reply count.

Global UI Events (CometChatMessageEvents)

CometChatThreadHeader does not emit its own global UI events. The parent message updates are handled internally via the ThreadHeaderViewModel, which listens for message edits, deletes, and reaction changes on the parent message.

SDK Events (Real-Time, Automatic)

The component listens to SDK events internally via its ViewModel. No manual attachment needed.
SDK ListenerInternal behavior
Message editedUpdates the parent message bubble if the parent message is edited
Message deletedUpdates the parent message bubble if the parent message is deleted
Reply count changedUpdates the reply count indicator when new replies are added
Automatic: parent message changes and reply count updates reflect in real time.

Functionality

Small functional customizations such as toggling visibility of UI elements and configuring alignment.
MethodDescriptionCode
setReactionVisibilityShows or hides reactions on the parent message bubble.setReactionVisibility(View.GONE)
setAvatarVisibilityShows or hides the avatar in the thread header.setAvatarVisibility(View.GONE)
setReceiptsVisibilityShows or hides read receipts on the parent message bubble.setReceiptsVisibility(View.GONE)
setReplyCountVisibilityShows or hides the reply count text.setReplyCountVisibility(View.GONE)
setReplyCountBarVisibilityShows or hides the reply count bar/layout.setReplyCountBarVisibility(View.GONE)
setMaxHeightSets the maximum height limit for the thread header in pixels.setMaxHeight(500)
setAlignmentSets bubble alignment: STANDARD (left/right by message type) or LEFT_ALIGNED (all left).setAlignment(UIKitConstants.MessageListAlignment.LEFT_ALIGNED)
  • Verify: After calling a visibility method, confirm the corresponding UI element is shown or hidden.

Custom View Slots

CometChatThreadHeader does not use the traditional ViewHolderListener pattern for view slots. Instead, it uses CometChatMessageTemplate to customize how the parent message bubble is rendered.

setTemplates

Replaces the default list of message templates used to render the parent message bubble.
val customTemplates: List<CometChatMessageTemplate> = listOf(myCustomTemplate)
threadHeader.setTemplates(customTemplates)
What this does: Replaces the entire set of message templates. The parent message bubble renders using the custom template configuration. If you pass an empty list, no message bubble renders.

addTemplate

Adds a single message template to the existing list without replacing defaults.
threadHeader.addTemplate(myCustomTemplate)
What this does: Appends a new CometChatMessageTemplate to the existing template list. Use this when you want to support an additional message type without removing the built-in templates.
  • Verify: After calling setTemplates or addTemplate, confirm the parent message bubble renders using the custom template configuration.

Common Patterns

Hide reactions on the parent message

threadHeader.setReactionVisibility(View.GONE)

Left-align all message bubbles

threadHeader.setAlignment(UIKitConstants.MessageListAlignment.LEFT_ALIGNED)

Custom time format

threadHeader.setTimeFormat(SimpleDateFormat("hh:mm a", Locale.getDefault()))

Hide reply count and reply count bar

threadHeader.setReplyCountVisibility(View.GONE)
threadHeader.setReplyCountBarVisibility(View.GONE)

Advanced Methods

setParentMessage

Sets the parent message for the thread header. This is required — the component will not render without it.
threadHeader.setParentMessage(baseMessage)

setTemplates

Replaces the default list of message templates used to render the parent message bubble.
threadHeader.setTemplates(customTemplateList)

addTemplate

Adds a single message template to the existing list.
threadHeader.addTemplate(customTemplate)

setTextFormatters

Adds custom text formatters to the current list of formatters used in the thread header.
threadHeader.setTextFormatters(listOf(myCustomFormatter))

setTimeFormat

Sets a custom time format for the parent message display.
threadHeader.setTimeFormat(SimpleDateFormat("hh:mm a", Locale.getDefault()))

setAlignment

Sets the bubble alignment for the parent message.
threadHeader.setAlignment(UIKitConstants.MessageListAlignment.LEFT_ALIGNED)
In STANDARD mode, the bubble appears on the left or right based on whether the message is incoming or outgoing. In LEFT_ALIGNED mode, all bubbles appear on the left.

Internal Access

These methods provide direct access to internal components for advanced use cases.
MethodReturnsDescription
getRecyclerView()RecyclerViewThe RecyclerView used for the parent message bubble
getBinding()CometchatThreadHeaderBindingThe ViewBinding for the component’s root layout
getThreadedHeaderViewModel()ThreadHeaderViewModelThe ViewModel managing thread header state
getAdapter()MessageAdapterThe adapter powering the parent message RecyclerView

Bubble Style Methods

MethodTypeDescription
setIncomingMessageBubbleStyle@StyleRes intSets the style for incoming message bubbles
setOutgoingMessageBubbleStyle@StyleRes intSets the style for outgoing message bubbles
Use internal access methods 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 CometChatThreadHeaderStyle in themes.xml, then apply with setStyle().
themes.xml
    <style name="CustomOutgoingMessageBubbleStyle" parent="CometChatOutgoingMessageBubbleStyle">
        <item name="cometchatMessageBubbleBackgroundColor">#F76808</item>
    </style>
    <style name="CustomIncomingMessageBubbleStyle" parent="CometChatIncomingMessageBubbleStyle">
        <item name="cometchatMessageBubbleBackgroundColor">#F76808</item>
    </style>

    <style name="CustomThreadHeaderStyle" parent="CometChatThreadHeaderStyle">
        <item name="cometchatThreadHeaderOutgoingMessageBubbleStyle">@style/CustomOutgoingMessageBubbleStyle</item>
        <item name="cometchatThreadHeaderIncomingMessageBubbleStyle">@style/CustomIncomingMessageBubbleStyle</item>
        <item name="cometchatThreadHeaderBackgroundColor">#FEEDE1</item>
        <item name="cometchatThreadHeaderReplyCountTextColor">#F76808</item>
        <item name="cometchatThreadHeaderReplyCountBackgroundColor">#FEEDE1</item>
    </style>
threadHeader.setStyle(R.style.CustomThreadHeaderStyle)
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:
MethodTypeDescription
setReplyCountBackgroundColor@ColorInt intBackground color of the reply count view
setReplyCountTextColor@ColorInt intText color of the reply count view
setReplyCountTextAppearance@StyleRes intText appearance of the reply count view
setIncomingMessageBubbleStyle@StyleRes intStyle for incoming message bubbles
setOutgoingMessageBubbleStyle@StyleRes intStyle for outgoing message bubbles

Customization Matrix

What to changeWhereProperty/APIExample
Parent messageActivity/FragmentsetParentMessage(BaseMessage)threadHeader.setParentMessage(baseMessage)
Reaction visibilityActivity/FragmentsetReactionVisibility(int).setReactionVisibility(View.GONE)
Avatar visibilityActivity/FragmentsetAvatarVisibility(int).setAvatarVisibility(View.GONE)
Receipt visibilityActivity/FragmentsetReceiptsVisibility(int).setReceiptsVisibility(View.GONE)
Reply count visibilityActivity/FragmentsetReplyCountVisibility(int).setReplyCountVisibility(View.GONE)
Reply count bar visibilityActivity/FragmentsetReplyCountBarVisibility(int).setReplyCountBarVisibility(View.GONE)
Max heightActivity/FragmentsetMaxHeight(int).setMaxHeight(500)
Bubble alignmentActivity/FragmentsetAlignment(MessageListAlignment).setAlignment(UIKitConstants.MessageListAlignment.LEFT_ALIGNED)
Time formatActivity/FragmentsetTimeFormat(SimpleDateFormat).setTimeFormat(new SimpleDateFormat("hh:mm a", Locale.getDefault()))
Text formattersActivity/FragmentsetTextFormatters(List).setTextFormatters(formatterList)
Message templates (replace)Activity/FragmentsetTemplates(List<CometChatMessageTemplate>).setTemplates(templateList)
Message templates (add)Activity/FragmentaddTemplate(CometChatMessageTemplate).addTemplate(template)
Outgoing bubble stylethemes.xmlcometchatThreadHeaderOutgoingMessageBubbleStyle<item name="cometchatThreadHeaderOutgoingMessageBubbleStyle">@style/CustomOutgoingStyle</item>
Incoming bubble stylethemes.xmlcometchatThreadHeaderIncomingMessageBubbleStyle<item name="cometchatThreadHeaderIncomingMessageBubbleStyle">@style/CustomIncomingStyle</item>
Header background colorthemes.xmlcometchatThreadHeaderBackgroundColor<item name="cometchatThreadHeaderBackgroundColor">#FEEDE1</item>
Reply count text colorthemes.xmlcometchatThreadHeaderReplyCountTextColor<item name="cometchatThreadHeaderReplyCountTextColor">#F76808</item>
Reply count background colorthemes.xmlcometchatThreadHeaderReplyCountBackgroundColor<item name="cometchatThreadHeaderReplyCountBackgroundColor">#FEEDE1</item>
Apply a custom styleActivity/FragmentsetStyle(int styleRes)threadHeader.setStyle(R.style.CustomThreadHeaderStyle)
Incoming bubble style (programmatic)Activity/FragmentsetIncomingMessageBubbleStyle(int).setIncomingMessageBubbleStyle(R.style.CustomIncomingStyle)
Outgoing bubble style (programmatic)Activity/FragmentsetOutgoingMessageBubbleStyle(int).setOutgoingMessageBubbleStyle(R.style.CustomOutgoingStyle)
Reply count background (programmatic)Activity/FragmentsetReplyCountBackgroundColor(int).setReplyCountBackgroundColor(Color.parseColor("#FEEDE1"))
Reply count text color (programmatic)Activity/FragmentsetReplyCountTextColor(int).setReplyCountTextColor(Color.parseColor("#F76808"))
Reply count text appearance (programmatic)Activity/FragmentsetReplyCountTextAppearance(int).setReplyCountTextAppearance(R.style.CustomTextAppearance)
Internal adapter accessActivity/FragmentgetAdapter()Advanced use only

Accessibility

The component renders a RecyclerView containing the parent message bubble. The reply count text is readable by screen readers. Avatar images include content descriptions derived from the sender’s name. For custom message templates provided via setTemplates or addTemplate, ensure you set android:contentDescription on visual-only elements so TalkBack can announce them. The default templates handle this automatically. Reaction indicators and read receipts are visual-only by default. If screen reader descriptions are needed, provide them via custom templates with appropriate contentDescription attributes.

Next Steps