Skip to main content
FieldValue
Packagecom.cometchat:chat-uikit-android
Key classCometChatTextFormatter (abstract base class for custom formatters)
Required setupCometChatUIKit.init() then CometChatUIKit.login("UID")
PurposeExtend to create custom inline text patterns with tracking characters, suggestion lists, and span formatting
FeaturesTracking character activation, suggestion list, span formatting per context (composer, bubbles, conversations), pre-send hooks
Sample appGitHub
RelatedMentions Formatter | ShortCut Formatter | All Guides
CometChatTextFormatter is an abstract class for formatting text in the message composer and message bubbles. Extend it to build custom formatters — hashtags, shortcuts, or any pattern triggered by a tracking character.
CapabilityDescription
Tracking characterActivates the formatter when the user types a specific character (e.g., #, !)
Suggestion listPopulates a dropdown of SuggestionItem objects as the user types
Span formattingApplies SpannableStringBuilder spans per context: composer, left/right bubbles, conversations
Pre-send hookhandlePreMessageSend lets you modify the message before it’s sent
Component integrationPlugs into any component via setTextFormatters()

Steps

1. Create a class extending CometChatTextFormatter

Pass your tracking character to the superclass constructor.

2. Override the search method

Called when the user types after the tracking character. Match input against your data and update the suggestion list.

3. Override onScrollToBottom

Required by the base class. Implement pagination logic or leave empty.

4. Override span formatting methods (optional)

Customize how matched text renders in different contexts using SpannableStringBuilder.

5. Integrate with a component

Pass the same list to CometChatMessageList and CometChatConversations via their setTextFormatters() methods to apply formatting across all contexts.

Methods Reference

MethodDescription
search(Context, String)Abstract — called when user types after the tracking character. Update the suggestion list here.
onScrollToBottom()Abstract — called when the suggestion list scrolls to the bottom. Implement pagination or leave empty.
onItemClick(Context, SuggestionItem, User, Group)Called when a suggestion item is selected. Override to customize insertion behavior.
handlePreMessageSend(Context, BaseMessage)Called before a message is sent. Override to modify the message (e.g., add metadata).
prepareLeftMessageBubbleSpan(Context, BaseMessage, SpannableStringBuilder)Override to format text in incoming message bubbles.
prepareRightMessageBubbleSpan(Context, BaseMessage, SpannableStringBuilder)Override to format text in outgoing message bubbles.
prepareComposerSpan(Context, BaseMessage, SpannableStringBuilder)Override to format text in the message composer.
prepareConversationSpan(Context, BaseMessage, SpannableStringBuilder)Override to format text in the conversations list preview.
setSuggestionItemList(List<SuggestionItem>)Updates the suggestion dropdown with new items.
setDisableSuggestions(boolean)Disables the suggestion dropdown entirely. (protected — accessible from subclasses only.)
setInfoText(String)Sets informational text displayed above the suggestion list.
setInfoVisibility(boolean)Toggles visibility of the info text.
setShowLoadingIndicator(boolean)Shows/hides a loading spinner in the suggestion dropdown.
getTrackingCharacter()Returns the tracking character passed to the constructor.

Next Steps

Mentions Formatter

Built-in @mention formatting with styled tokens

ShortCut Formatter

Shortcut text expansion via the message-shortcuts extension

All Guides

Browse all feature and formatter guides

Sample App

Full working sample application on GitHub