Skip to content

Instantly share code, notes, and snippets.

@hector6872
Created January 28, 2019 18:20
Show Gist options
  • Save hector6872/13fc6397311b5c0d052de010e3d2fcee to your computer and use it in GitHub Desktop.
Save hector6872/13fc6397311b5c0d052de010e3d2fcee to your computer and use it in GitHub Desktop.
BindableRecyclerView for Kotlin
abstract class BindableAdapter<TYPE : MultiType>(private val list: MutableList<TYPE>) : RecyclerView.Adapter<BindableViewHolder<TYPE>>() {
override fun onBindViewHolder(
holder: BindableViewHolder<TYPE>,
position: Int
) = holder.bind(list[position])
override fun getItemViewType(position: Int): Int = list[position].type
override fun getItemCount(): Int = list.size
}
abstract class BindableViewHolder<TYPE>(itemView: View) : RecyclerView.ViewHolder(itemView) {
abstract fun bind(element: TYPE)
}
interface MultiType {
val type: Int
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment