相同的两种不同实现:
class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
val textView: TextView = v.findViewById(R.id.textView)
fun bind(model: Model) {
textView.text = model.name
}
}
class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
fun bind(model: Model) {
itemView.apply {
textView.text = model.name
}
}
}
对于片段和活动,通过合成缓存链接调用 View 元素(即 findViewById 在内部只发生一次),但在 ViewHolder 内部,它是如何工作的?一切还好吗?或者每次我们滚动时,都会发生 findViewById ?
媒体上说
这可能意味着一切都很好:) 但已弃用(更好的老式方式,findViewById)