我没有问题可以保存项目ID并检索它们,问题是 当我尝试通过检查onBindView方法中的项目ID来显示在recyclerview中保存为收藏夹的项目时,它显示仅一个项目被保存为收藏夹。
onBindView代码如下:
if(searchIfInFav(modelShipment.getShipmentsKey())) {
Log.d(TAG, "onBindViewHolder: checkStatus " + searchIfInFav(modelShipment.getShipmentsKey()));
shipmentsViewHolder.save_later.setTag(R.drawable.saved_for_later);
shipmentsViewHolder.save_later.setImageResource(R.drawable.saved_for_later);
}else {
shipmentsViewHolder.save_later.setTag(R.drawable.save);
shipmentsViewHolder.save_later.setImageResource(R.drawable.save);
}
和以下迭代器方法:
private boolean searchIfInFav(String key) {
boolean match = false;
for(String mKey : similarKeys){
Log.d(TAG, "onBindViewHolder: checkStatus loop " + mKey);
if(mKey.equals(key)){
match = true;
}else {
match = false;
}
}
return match;
}
尽管列表具有更多ID,但imageButton仅填充了一项。