Created
May 1, 2020 13:14
-
-
Save baggednismo/83e0f5ba227a0554343a90bffb8dee2b to your computer and use it in GitHub Desktop.
This file contains 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
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