Skip to content

Instantly share code, notes, and snippets.

@baggednismo
Last active May 1, 2020 13:31
Show Gist options
  • Save baggednismo/f7182fdc7a6f2e644aee0b7b4d1ac5fd to your computer and use it in GitHub Desktop.
Save baggednismo/f7182fdc7a6f2e644aee0b7b4d1ac5fd to your computer and use it in GitHub Desktop.
class ChildItemsViewHolder(inflater: LayoutInflater, parent: ViewGroup, itemListener: ItemListener) :
RecyclerView.ViewHolder(inflater.inflate(R.layout.card_child_item, parent, false)), View.OnClickListener {
private var itemListener: ItemListener? = null
private var cardTitle: TextView? = null
private var cardDesc: TextView? = null
private var remove: ConstraintLayout? = null
init {
cardTitle = itemView.findViewById(R.id.card_title)
cardDesc = itemView.findViewById(R.id.card_desc)
remove = itemView.findViewById(R.id.remove)
this.itemListener = itemListener
}
fun bind(card: ChildItemModel) {
cardTitle?.text = card.error_type
cardDesc?.setText("Reported: ${card.reported_date}")
itemView.setOnClickListener(this)
remove?.setOnClickListener(this)
}
override fun onClick(v: View?) {
when (v?.id) {
R.id.remove -> itemListener?.onRemoveCard(adapterPosition)
else -> itemListener?.onViewCard(adapterPosition)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment