gpt4 book ai didi

android - Recycler View 重复背景颜色

转载 作者:行者123 更新时间:2023-12-05 00:20:02 25 4
gpt4 key购买 nike

我在回收站 View 中有一个歌曲列表。我需要更改之前播放的行的背景颜色。

所以在我的onBindViewHolder我有这个。

               if(activeAudioIndex > activeList.indexOf(currentSong)) {
currentRow.setBackgroundColor(R.color.colorPink)
}

在这个 activeAudioIndex是播放歌曲的实际索引。
activeList是用于recyclerView的数组

但我可以看到更改的背景颜色重复不必要的行。当我向下滚动时。

如何解决这个问题?

最佳答案

您还需要添加“其他”部分。所以你的代码应该是这样的:

if(activeAudioIndex > activeList.indexOf(currentSong)) {
currentRow.setBackgroundColor(R.color.colorPink)
} else {
//DEFAULT BACKGROUND COLOR
currentRow.setBackgroundColor(R.color.another_color)
}

关于android - Recycler View 重复背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61461633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com