I'm new in kotlin ,this is my adapter code , it works find and I've no problem , now ,I need to implement click listener for it , here is my code :
class CategoryAdapter(val context: Context,val list: List<CategoryItems>): RecyclerView.Adapter<CategoryAdapter.ViewHolder>() {
var typeface: Typeface? = Func.getTypeFace(context)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
var catRow=list.get(position)
holder?.tvTitle.text = catRow.name
holder?.tvTitle.setTypeface(typeface)
Glide.with(context).load(Const.BaseUrl+"Opitures/"+ catRow.icon_name).into(holder?.imgCat);
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val v = LayoutInflater.from(parent?.context).inflate(R.layout.category_item, parent, false)
return ViewHolder(v);
}
override fun getItemCount(): Int {
return list.size
}
class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView){
val tvTitle = itemView.findViewById<TextView>(R.id.tv_cat_title)
val imgCat = itemView.findViewById<ImageView>(R.id.img_cat)
}
}
I want to add click listener, I used to do it in viewholder class where I implement click listener
how can I do it in kotlin , ? i've tied so many ways but no success