Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
class MessageAdapter(val messages: ArrayList<Message>, val itemClick: (Message) -> Unit) :
RecyclerView.Adapter<MessageAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.message_item, parent, false)
return ViewHolder(view, itemClick)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
override fun getItemCount() = messages.size
class ViewHolder(view: View, val itemClick: (Message) -> Unit) : RecyclerView.ViewHolder(view) {
fun bindForecast(message: Message) {
with(message) {
itemView.messageAdapterMessageItem.text = message.text
itemView.setOnClickListener { itemClick(this) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment