Text formatters let you process message text with tracking characters, suggestion lists, and spannable transformations. Use them to add hashtag detection, custom mentions, link previews, or any text pattern processing. Both modules have their ownDocumentation Index
Fetch the complete documentation index at: https://cometchat-22654f5b-docs-android-v6-beta2.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
CometChatTextFormatter class with the same API pattern:
- Kotlin XML:
com.cometchat.uikit.kotlin.shared.formatters.CometChatTextFormatter - Jetpack Compose:
com.cometchat.uikit.compose.presentation.shared.formatters.CometChatTextFormatter
CometChatTextFormatter API
The abstract class takes atrackingCharacter that triggers the formatter when typed in the composer (e.g., @ for mentions, # for hashtags).
Key Override Methods
| Method | Purpose |
|---|---|
search(context, queryString) | Called when the user types after the tracking character. Fetch and display suggestions. |
onScrollToBottom() | Called when the user scrolls to the bottom of the suggestion list. Use for pagination. |
prepareLeftMessageBubbleSpan(context, message, spannable) | Apply spans to text in incoming message bubbles. |
prepareRightMessageBubbleSpan(context, message, spannable) | Apply spans to text in outgoing message bubbles. |
prepareComposerSpan(context, message, spannable) | Apply spans to text in the message composer. |
prepareConversationSpan(context, message, spannable) | Apply spans to the last message preview in the conversation list. |
handlePreMessageSend(context, message) | Modify a message before it’s sent (attach metadata, transform text). |
onItemClick(context, suggestionItem, user, group) | Called when the user selects a suggestion item. |
Suggestion System
| Method | Description |
|---|---|
setSuggestionItemList(items) | Set the list of suggestions to display |
setShowLoadingIndicator(show) | Show/hide a loading spinner in the suggestion dropdown |
setDisableSuggestions(disable) | Disable the suggestion dropdown entirely |
Example: Custom Hashtag Formatter
- Kotlin (XML Views)
- Jetpack Compose
Registering Formatters
- Kotlin (XML Views)
- Jetpack Compose
Built-in Formatter: CometChatMentionsFormatter
The UI Kit includesCometChatMentionsFormatter as a built-in formatter that handles @mention detection, user suggestion lists, and spannable highlighting. It’s automatically added to components when mentions are enabled.
Each module has its own implementation:
- Kotlin XML:
com.cometchat.uikit.kotlin.shared.formatters.CometChatMentionsFormatter - Jetpack Compose:
com.cometchat.uikit.compose.presentation.shared.formatters.CometChatMentionsFormatter
Related
- Mentions Formatter Guide — Built-in mentions formatter reference.
- Customization Overview — See all customization categories.