I have this code for my adapter.
class AdapterPendingCases(private val values: MutableList<String>):RecyclerView.Adapter<AdapterPendingCases.PendingCasesViewHolder>() {
override fun getItemCount()=values.size
inner class PendingCasesViewHolder constructor(itemView: View):RecyclerView.ViewHolder(itemView) {
private val briefDescription=itemView.findViewById<TextView>(R.id.briefDescription)
private val currData=itemView.findViewById<TextView>(R.id.currData)
val deleteItem=itemView.findViewById<ImageView>(R.id.deleteItem) //надо как-то переделать с помощью ButterKnife
fun bind(item:String) {
briefDescription.text=item
val date = getCurrentDateTime()
val dateInString = date.toString("yyyy/MM/dd HH:mm:ss")
currData.text= dateInString
}
private fun Date.toString(format: String, locale: Locale = Locale.getDefault()): String {
val formatter = SimpleDateFormat(format, locale)
return formatter.format(this)
}
private fun getCurrentDateTime(): Date {
return Calendar.getInstance().time
}
fun deleteClick(View: View) {
values.removeAt(adapterPosition)
notifyDataSetChanged()
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PendingCasesViewHolder{
return PendingCasesViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_pending_cases, parent, false))}
override fun onBindViewHolder(holder: PendingCasesViewHolder, position: Int) {
holder.bind(values[position])
}
fun delAndUpdate(position: Int) {
values.removeAt(position)
notifyDataSetChanged()
}
i want to use Butterknife and use @OnClick for deleteItem. Now i can't link a click for my deleteItem. I am ready to listen to other recommendations on the code. p.s. in the project Butterknife work correctly.