How to use ViewBinding in a RecyclerView.Adapter?

前端 未结 7 2135
小鲜肉
小鲜肉 2021-02-05 01:59

Can I use ViewBindings to replace findViewById in this typical RecyclerView.Adapter initialization code? I can\'t set a binding val in the

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-05 02:29

    just pass your model calss into xml and set these data into xml this code look fine and add a method where you add these data into binding like you don,t need to fine the id for this

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.setData(listData[position])
    
    }
    
    
    fun setData(model: ListData) {
            with(binding) {
                data = model
                executePendingBindings()
            }
        }
    

提交回复
热议问题