Created
January 28, 2019 18:20
-
-
Save hector6872/13fc6397311b5c0d052de010e3d2fcee to your computer and use it in GitHub Desktop.
BindableRecyclerView for Kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface MultiType { | |
val type: Int | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment