Chat UIKit Android View v3
Chat UIKit Android View
Chat UIKit
Android View
Version 3

Customize message click events

Copy link

Sendbird UIKit provides a basic interface that can receive events for each area of the message UI.


Types of events

Copy link

The following are types of message click events that UIKit for Android provides.

Message click events

Message click

Message mention click

Message profile click

Quote reply click

Thread info click

Emoji reaction click


Register events

Copy link

There are two ways to receive events as shown below. Note that click events are only invoked in default Views provided by the UIKit. Consequently, events occurring within custom view are not received.

  1. Through Builder
  2. Using a custom fragment

Note: If events are registered using the Builder and the app is forcibly terminated due to memory shortages, the registered custom events may be lost. To avoid such loss, inherit from the fragment when constructing a screen for multiple uses.

Receive events through Builder

Copy link

The following code shows an example of how events can be received through the builder.

val fragment = ChannelFragment.Builder(channelUrl)
    .setOnMessageLongClickListener { view, _, _ ->
        Toast.makeText(view.context, "Message Long Click Sample", Toast.LENGTH_SHORT).show()
    }
    /*
    .setOnMessageClickListener { view, position, data ->  }
    .setOnMessageMentionClickListener { view, position, data ->  }
    .setOnMessageProfileClickListener{ view, position, data ->  }
    .setOnMessageProfileLongClickListener{ view, position, data ->  }
    .setOnQuoteReplyMessageClickListener{ view, position, data ->  }
    .setOnQuoteReplyMessageLongClickListener{ view, position, data ->  }
    .setOnThreadInfoClickListener{ view, position, data ->  }
    .setEmojiReactionClickListener { view, position, message, reactionKey ->  }
    .setEmojiReactionLongClickListener { view, position, message, reactionKey ->  }
      */
    .build()

Receive events using a custom fragment

Copy link

In Fragments, you can override the predefined functions, and specify a custom behavior instead.

Note: For events related to reactions, you should register them within the message list component.

class MessageClickSampleFragment : ChannelFragment() {
    override fun onMessageClicked(view: View, position: Int, message: BaseMessage) {
        Toast.makeText(requireContext(), "Message Click Sample", Toast.LENGTH_SHORT).show()
        super.onMessageClicked(view, position, message)
    }

    /*
    override fun onMessageLongClicked(view: View, position: Int, message: BaseMessage) {
        super.onMessageLongClicked(view, position, message)
    }

    override fun onMessageProfileClicked(view: View, position: Int, message: BaseMessage) {
        super.onMessageProfileClicked(view, position, message)
    }

    override fun onMessageProfileLongClicked(view: View, position: Int, message: BaseMessage) {
        super.onMessageProfileLongClicked(view, position, message)
    }

    override fun onMessageMentionClicked(view: View, position: Int, user: User) {
        super.onMessageMentionClicked(view, position, user)
    }

    override fun onQuoteReplyMessageClicked(view: View, position: Int, message: BaseMessage) {
        super.onQuoteReplyMessageClicked(view, position, message)
    }

    override fun onQuoteReplyMessageLongClicked(view: View, position: Int, message: BaseMessage) {
        super.onQuoteReplyMessageLongClicked(view, position, message)
    }

    override fun onThreadInfoClicked(view: View, position: Int, message: BaseMessage) {
        super.onThreadInfoClicked(view, position, message)
    }
    */
}

For an in-depth practical demonstration, see our sample code.