android - 如何在视图绑定中的活动中获取回收者视图当前项目文本值
问题描述
我有一个回收器视图,我需要获取由文本视图和其他视图组成的当前 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到活动的价值
解决方案
我认为您应该在这里使用用户界面。
推荐阅读
- c - 程序完成时分支预测器条目失效?
- node.js - 如何使用 node js 客户端查询弹性搜索
- javascript - 如何在颤振中使用 javascript 云函数发送 fcm 通知?
- c# - 运行 BenchmarkDotNet 时出现“错误的程序集绑定重定向”
- c++17 - 存储一个捕获这个的 lambda
- c - C 编程中的 Sqlite
- html - 如何解决 body 属性以在 Codepen 的 CSS 中显示颜色?
- python - Django 提供静态文件,即使在 Debug 关闭且没有 Web 服务器设置为服务的情况下
- r - 错误:n() 只能在数据上下文中调用(包冲突)
- javascript - 显示和隐藏元素列表时,在页面的其余部分平滑 Nuxt/Vue 过渡