Skip to content

Instantly share code, notes, and snippets.

@baggednismo
Created May 1, 2020 13:14
Show Gist options
  • Save baggednismo/83e0f5ba227a0554343a90bffb8dee2b to your computer and use it in GitHub Desktop.
Save baggednismo/83e0f5ba227a0554343a90bffb8dee2b to your computer and use it in GitHub Desktop.
class ChildItemsAdapter(private val data: ArrayList<ChildItemModel>,
private var itemListener: ItemListener
) : RecyclerView.Adapter<ChildItemsViewHolder>(), ItemListener {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChildItemsViewHolder {
val inflater = LayoutInflater.from(parent.context)
return ChildItemsViewHolder(inflater, parent, this)
}
override fun onBindViewHolder(holder: ChildItemsViewHolder, position: Int) {
val card: ChildItemModel = data[position]
holder.bind(card)
}
override fun getItemCount() = data.size
// We dont want this here but we trap if for the onRemoveCard below
// Use the calling class listener
override fun onViewCard(position: Int) {
itemListener?.onViewCard(position)
}
override fun onRemoveCard(position: Int) {
data.removeAt(position)
notifyDataSetChanged()
itemListener?.onRemoveCard(position)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment