Skip to content

Instantly share code, notes, and snippets.

@junsuk5
Last active May 30, 2019 07:29
Show Gist options
  • Save junsuk5/113b3bc2b91b00e6b3ff1c5edfe72024 to your computer and use it in GitHub Desktop.
Save junsuk5/113b3bc2b91b00e6b3ff1c5edfe72024 to your computer and use it in GitHub Desktop.
Kotlin용 리사이클러 어댑터 라이브템플릿. DataBinding 적용 필수
class $class$(private val clickListener: (item: $model$) -> Unit) :
RecyclerView.Adapter<$class$.$holder$>() {
var items = arrayListOf<$model$>()
class $holder$(val binding: $binding$) : RecyclerView.ViewHolder(binding.root)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): $holder$ {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.$layout$, parent, false)
val viewHolder = $holder$($binding$.bind(view))
view.setOnClickListener {
clickListener.invoke(items[viewHolder.adapterPosition])
}
return viewHolder
}
override fun getItemCount() = items.size
override fun onBindViewHolder(holder: $holder$, position: Int) {
holder.binding.$var$ = items[position]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment