Skip to content

Instantly share code, notes, and snippets.

@xloger
Created April 19, 2018 02:34
Show Gist options
  • Save xloger/c53939f3017967da99f5b32446bee036 to your computer and use it in GitHub Desktop.
Save xloger/c53939f3017967da99f5b32446bee036 to your computer and use it in GitHub Desktop.
class SimpleAdapter<T>(val list: List<T>, val layoutResource: Int, val bind: (holder: ViewHolder, t : T) -> Unit) : RecyclerView.Adapter<SimpleAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(parent.context).inflate(layoutResource, parent, false))
}
override fun getItemCount(): Int = list.size
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
bind(holder, list[position])
}
class ViewHolder(view: View) : RecyclerView.ViewHolder(view)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment