我对图像有问题,我正在尝试从列表中的服务器获取图像,但是如果我从应用程序更新图像,则它会成功进入服务器,但是当我获取新数据时,我得到的是旧图像,我已经清除了Picasso
缓存显示内存中仍旧的图像
这是我的代码。是否有其他解决方案可清除Picasso
public class WorkerListAdapter extends RecyclerView.Adapter<WorkerListAdapter.MyViewHolder> {
private static final int REQUEST_PHONE_CALL = 1;
private List<ItemWorkerList> itemWorkerListList;
private Context context;
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView tv_worker_name, tv_worker_type;
public CircleImageView iv_worker_image;
public ImageView iv_worker_images;
ImageView iv_edit_provider;
public LinearLayout ll_doc;
public ProgressBar pb_worker;
public MyViewHolder(View view) {
super(view);
this.setIsRecyclable(true);
tv_worker_name = (TextView) view.findViewById(R.id.tv_worker_name);
tv_worker_type = (TextView) view.findViewById(R.id.tv_worker_type);
iv_edit_provider = (ImageView) view.findViewById(R.id.iv_edit_provider);
iv_worker_image = (CircleImageView) view.findViewById(R.id.iv_worker_image);
iv_edit_provider = (ImageView) view.findViewById(R.id.iv_edit_provider);
pb_worker = (ProgressBar) view.findViewById(R.id.pb_worker);
}
}
public WorkerListAdapter(Context context, ArrayList<ItemWorkerList> itemWorkerListList) {
this.context = context;
this.itemWorkerListList = itemWorkerListList;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_worker_list, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
final ItemWorkerList itemWorkerList = itemWorkerListList.get(position);
holder.tv_worker_name.setText(itemWorkerList.getName());
holder.tv_worker_type.setText(itemWorkerList.getCategory());
Picasso.get().invalidate(itemWorkerList.getImage());
Picasso.get().invalidate(itemWorkerList.getDocument());
if (!TextUtils.isEmpty(itemWorkerList.getImage())) {
Picasso.get().load(itemWorkerList.getImage()).memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).into(holder.iv_worker_image, new Callback() {
@Override
public void onSuccess() {
holder.pb_worker.setVisibility(View.GONE);
}
@Override
public void onError(Exception e) {
holder.pb_worker.setVisibility(View.GONE);
Picasso.get().load(R.drawable.dummy).into(holder.iv_worker_image);
}
});
}
答案 0 :(得分:0)
您可以执行此操作-
Picasso.with(context).load(your_url).networkPolicy(NetworkPolicy.NO_CACHE)
.memoryPolicy(MemoryPolicy.NO_CACHE)
.into(your_image_view);
答案 1 :(得分:0)
如@Murtaza所说
public class Clear {
public static void clearCache (Picasso p) {
p.cache.clear();
}}
像这样使用。
Clear.clearCache(Picasso.with(context));
Clear类必须位于包中:
因为无法从该程序包外部访问缓存。就像这个答案一样:https://stackoverflow.com/a/23544650/4585226