如何让回收者在 VIEW BINDING 中查看活动中的当前项目文本值

问题描述

我有一个回收器视图,我需要获取由文本视图和其他视图组成的 recyclerView 当前项的值。在视图绑定之前,它非常简单,如下所示:

recyclerview.findViewHolderForAdapterPosition(i)!!.itemView.mDescription.text.toString()

现在在 recyclerView 适配器中启用视图绑定后,我无法从活动访问 editTextDescription。 任何帮助表示赞赏。

这是我的适配器,其中包含 textView、editText、复选框等。我想要的是,在单击 Activity 中的按钮时,它应该从特定位置的项目的 recyclerView 适配器(listadapter获取数据并提交它到 REST api。

class SpiranAdapter(private val list: List<Spiran>)
    : RecyclerView.Adapter<SpiranViewHolder>() {
   override fun onBindViewHolder(holder: SpiranViewHolder,position: Int) {
        val spiran: Spiran = list[position]
        holder.bind(spiran)
    }
}
class SpiranViewHolder(inflater: LayoutInflater,parent: ViewGroup) :
    RecyclerView.ViewHolder(inflater.inflate(R.layout.list_item,parent,false)) {
    private var mTitleView: TextView? = null

    init {
        mTitleView = itemView.findViewById(R.id.list_title) // textView
        mYearView = itemView.findViewById(R.id.list_description) //textView
        mDescription = itemView.findViewById(R.id.description) // as EditText
        isServiceOpted = itemView.findViewById(R.id.isServiceOpted) // checkBox
    }
    fun bind(spiran: Spiran) {
        mTitleView?.text = spiran.title
        mYearView?.text = spiran.year.toString()
        mDescription?.setText(spiran.description);
        isServiceOpted as Checkable).isChecked = spiran.status
    }

}

除了复选框之外没有任何点击监听器。有 editText,我需要从那个 editText 到活动的价值

解决方法

我认为您应该在这里使用用户界面。