Skip to content

Instantly share code, notes, and snippets.

@illuzor
Created September 17, 2018 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save illuzor/e01c6798e5a7cf4d7ff9c216ab120de7 to your computer and use it in GitHub Desktop.
Save illuzor/e01c6798e5a7cf4d7ff9c216ab120de7 to your computer and use it in GitHub Desktop.
package com.illuzor.lesson.wallpapers.adapters
import androidx.recyclerview.widget.RecyclerView
abstract class AbstractAdapter<T, VH : RecyclerView.ViewHolder> : RecyclerView.Adapter<VH>() {
private val items = mutableListOf<T>()
protected lateinit var clickListener: (String) -> Unit
fun setOnclickListener(clickListener: (String) -> Unit) {
this.clickListener = clickListener
}
fun addItems(items: List<T>) {
this.items.addAll(items)
notifyDataSetChanged()
}
override fun getItemCount() = items.size
protected fun getItem(position: Int): T = items[position]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment