简体   繁体   English

“回收者”视图中的第一个可见项目将剩余列表

[英]First visible item in recycler view chagnes rest of the list

I have list of users with circle foreground on their avatar. 我的头像上有圆圈前景的用户列表。 If user is online circle is green, otherwise it is red. 如果用户在线,则圆圈为绿色,否则为红色。 The problem is, whole list is red (for example) until I scroll under the user which is supposed to be green. 问题是,整个列表是红色的(例如),直到我在应该是绿色的用户下滚动。

在此处输入图片说明

After that when I scroll back upwards whole list has green circles until I reach offline user which will change whole list back to red. 之后,当我向上滚动时,整个列表将显示绿色圆圈,直到到达离线用户为止,该用户将整个列表更改回红色。

在此处输入图片说明

My bind function looks like this: 我的绑定函数如下所示:

    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)
}

You need to call mutate on the drawable otherwise you're changing the shared instance : 您需要在drawable上调用mutate ,否则您将更改共享实例

val foreground = ContextCompat.getDrawable(itemView.context, R.drawable.ic_online)
                              .mutate()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM