Skip to main content
View Slots let you swap out specific parts of a component’s list item — the avatar area, title, subtitle, trailing section, or the entire row — while keeping the rest of the component’s behavior intact.

Available View Slots

SlotRegionDescription
leadingViewLeft sectionReplaces the avatar / leading area
titleViewTitle textReplaces the name / title text
subtitleViewSubtitle textReplaces the last message preview
trailingViewRight sectionReplaces the timestamp / badge area
itemViewEntire rowReplaces the entire list item layout
When you use itemView, all other slot setters are ignored since the entire row is replaced.

How It Works

Each list-based component defines a ViewHolderListener abstract class with two callbacks:
CallbackPurpose
createView(context, binding)Return a View for the slot. Called once when the ViewHolder is created.
bindView(context, createdView, data, ...)Bind data to your custom view. Called every time the item is bound.
Pass the listener to the component via setLeadingView(), setTitleView(), setSubtitleView(), setTrailingView(), or setItemView().

Example: Custom Leading View

Replace the default avatar with a custom view showing the first letter of the conversation name.
conversations.setLeadingView(object : ConversationsViewHolderListener() {
    override fun createView(
        context: Context,
        binding: CometchatConversationsListItemsBinding
    ): View {
        return TextView(context).apply {
            layoutParams = ViewGroup.LayoutParams(48.dp, 48.dp)
            gravity = Gravity.CENTER
            textSize = 18f
            setTextColor(Color.WHITE)
        }
    }

    override fun bindView(
        context: Context,
        createdView: View,
        conversation: Conversation,
        typingIndicator: TypingIndicator?,
        holder: RecyclerView.ViewHolder,
        conversations: List<Conversation>,
        position: Int
    ) {
        val textView = createdView as TextView
        val name = conversation.conversationWith?.name ?: ""
        textView.text = name.firstOrNull()?.uppercase() ?: "?"
        textView.background = GradientDrawable().apply {
            shape = GradientDrawable.OVAL
            setColor(Color.parseColor("#6851D6"))
        }
    }
})

Example: Custom Subtitle View

Show a custom last message format in the subtitle area.
conversations.setSubtitleView(object : ConversationsViewHolderListener() {
    override fun createView(
        context: Context,
        binding: CometchatConversationsListItemsBinding
    ): View {
        return TextView(context).apply {
            maxLines = 1
            ellipsize = TextUtils.TruncateAt.END
        }
    }

    override fun bindView(
        context: Context,
        createdView: View,
        conversation: Conversation,
        typingIndicator: TypingIndicator?,
        holder: RecyclerView.ViewHolder,
        conversations: List<Conversation>,
        position: Int
    ) {
        val textView = createdView as TextView
        // Show typing indicator if available
        if (typingIndicator != null) {
            textView.text = "typing..."
            return
        }
        textView.text = when (val msg = conversation.lastMessage) {
            is TextMessage -> msg.text
            is MediaMessage -> "📎 ${msg.attachment?.fileExtension ?: "Media"}"
            else -> "New conversation"
        }
    }
})

Toolbar Overflow Menu

Inject a custom view into the component’s toolbar area. This is separate from list item view slots.
val menuButton = ImageButton(context).apply {
    setImageResource(R.drawable.ic_filter)
    setOnClickListener { /* show filter dialog */ }
}
conversations.setOverflowMenu(menuButton)

Components with View Slots

View slots are available on all list-based components:
ComponentViewHolderListener (Kotlin XML)Composable Lambdas (Compose)
CometChatConversationsConversationsViewHolderListener(Conversation, TypingIndicator?) -> Unit
CometChatUsersUsersViewHolderListener(User) -> Unit
CometChatGroupsGroupsViewHolderListener(Group) -> Unit
CometChatGroupMembersGroupMembersViewHolderListener(GroupMember) -> Unit
CometChatCallLogsCallLogsViewHolderListener(CallLog) -> Unit
CometChatReactionListReactionListViewHolderListener(Reaction) -> Unit
CometChatMessageHeaderMessageHeaderViewHolderListener(User?, Group?) -> Unit