为了账号安全,请及时绑定邮箱和手机立即绑定

使用 Stream.of 检查 List<String> 是否开始使用另一个字符串

使用 Stream.of 检查 List<String> 是否开始使用另一个字符串

眼眸繁星 2022-01-19 09:32:46
我有 List 女巫包含两个不同的 url我的网址: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 的开头),但我的循环不像我想要的那样工作。我的开关图像代码:@Overridepublic 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();}@Overridepublic int getItemCount() {    return localArtistNameList.size();}我的问题是图标无法更改。我对其进行了调试,并且为了简单起见,我确实打印了屏幕:
查看完整描述

1 回答

?
慕桂英3389331

TA贡献2036条经验 获得超8个赞

使用此代码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();


查看完整回答
反对 回复 2022-01-19
  • 1 回答
  • 0 关注
  • 181 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号