RecyclerView:在recyclerview中显示标记为收藏的收藏项

时间:2019-11-20 15:05:28

标签: android android-recyclerview

我没有问题可以保存项目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仅填充了一项。

0 个答案:

没有答案