android - Kotlin如何枚举recyclerView中的每一行
问题描述
我正在使用 Kotlin,在 recyclerView 中我需要枚举每个加载的单元格(1、2、3 等)。我可以在 IOS 中通过在 cellForRowAt 下添加以下内容来做到这一点:
cell!.cellCount.text = "\(indexPath.row + 1)"
我还没有找到 Kotlin 的等价物,有什么建议吗?先感谢您。
解决方案
我已经用以下内容更新了我的代码。
内视图Holder
var cellCount = itemView.findViewById<TextView>(R.id.cellCountLbl)
onBindViewHolder 里面
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val indexRow = position + 1
holder.cellCount.text = indexRow.toString()
holder.bindPatList(youArray[position])
}
一切都按预期工作。谢谢
推荐阅读
- android - AppNotIdleException 由于 AnimatedVectorDrawableCompat
- javascript - CLUEDO CHALLENGE:使用函数内部的函数来检索数组中对象的随机键
- vb.net - 有没有办法将给定的属性标识符作为 VB 中的参数传递给 Sub?
- r - 使用 mutate() dplyr 计算平均值时出错
- outlook - 具有相同邮件地址的 Outllok 邮件帐户
- dask - 附加来自另一个数据帧的行
- reactjs - 如何从现有的 webform iis 托管应用程序链接到 react asp mvc 应用程序?
- mongodb - mongodb - 如何获取包含特定 DBRef 对象的所有集合
- scala - 如何根据一个字符和一个空格用 scala 拆分列
- php - 如何插入用户信誉 (IPS 4.3)