我有列表女巫包含两个不同的网址
我的网址:
https://is2-ssl.mzstatic.com/image/thumb/Music111/v4/31/5b/62/315b62fb-3b46-d2ee-5833-be210d3287f7/source/100x100bb.jpg
和
https://lastfm-img2.akamaized.net/i/u/300x300/5ed371a8b6d03258d597eb661805baee.png
我想在AdaperRecyclerView中切换图标图像(比较url的开头),但是我的循环无法正常运行。
我的切换图片代码:
@Override
public void onBindViewHolder(@NonNull SongHolder holder, int possition) {
// Source image swicher
holder.binding.setModelItem(localArtistNameList.get(possition));
if( Stream.of(localSourceList).anyMatch((s) -> s.startsWith("https://is"))){
holder.binding.sourceIcon.setBackgroundResource(R.drawable.icon_source_itune);
}else {
holder.binding.sourceIcon.setBackgroundResource(R.drawable.icon_source_lastfm);
}
holder.binding.executePendingBindings();
}
@Override
public int getItemCount() {
return localArtistNameList.size();
}
我的问题是图标无法更改。我将其装袋,为简单起见,我打印了屏幕:
答案 0 :(得分:1)
在onBindViewHolder
中使用此代码:
holder.binding.setModelItem(localArtistNameList.get(possition));
holder.binding.sourceIcon.setBackgroundResource(localArtistNameList.get(i).startWith("https://is") ? R.drawable.icon_source_itune : R.drawable.icon_source_lastfm);
holder.binding.executePendingBindings();