Android “回收器”视图中的第一个可见项将更改列表的其余部分
我有一个在他们的头像上有圆形前景的用户列表。若用户在线,圆圈为绿色,否则为红色。问题是,整个列表是红色的(例如),直到我滚动到应该是绿色的用户下方 之后,当我向上滚动时,整个列表都有绿色圆圈,直到我到达离线用户,离线用户会将整个列表变回红色 我的绑定函数如下所示:Android “回收器”视图中的第一个可见项将更改列表的其余部分,android,android-recyclerview,kotlin,Android,Android Recyclerview,Kotlin,我有一个在他们的头像上有圆形前景的用户列表。若用户在线,圆圈为绿色,否则为红色。问题是,整个列表是红色的(例如),直到我滚动到应该是绿色的用户下方 之后,当我向上滚动时,整个列表都有绿色圆圈,直到我到达离线用户,离线用户会将整个列表变回红色 我的绑定函数如下所示: fun bind(userInfo: UserInfo) { val foreground = ContextCompat.getDrawable(itemView.context, R.drawable.ic_
fun bind(userInfo: UserInfo) {
val foreground = ContextCompat.getDrawable(itemView.context, R.drawable.ic_online)
foreground?.colorFilter = PorterDuffColorFilter(ContextCompat.getColor(
itemView.context, when {
userInfo.status == Status.OFFLINE -> R.color.offline_red
else -> R.color.colorAccent
}), PorterDuff.Mode.SRC_ATOP)
itemView.profilePictureImageView.foreground = foreground
val options = RequestOptions()
options.placeholder(R.drawable.ic_default_avatar)
options.circleCrop()
Glide.with(itemView.context)
.load("http://scdb.abradio.cz/uploads/interprets/r/radek-rettegy.jpg")
.apply(options)
.into(itemView.profilePictureImageView)
}
您需要拨打:
看看
val foreground = ContextCompat.getDrawable(itemView.context, R.drawable.ic_online)
.mutate()