wifi关闭时,如何使用毕加索图像加载器从缓存中显示图像? [英] How to Display Image From cache using picasso image loader when wifi is off?
本文介绍了wifi关闭时,如何使用毕加索图像加载器从缓存中显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用毕加索图像加载器从url显示图像,它可以正常工作,但是当wifi处于关闭状态时,我不会从缓存中显示图像.
Display Image from url using picasso image loader,it working fine but i wont display image from cache when wifi is off state.
ImageView photo=(ImageView)findViewByid(R.id.photo);
Picasso.with(context)
.load("thumburl")
.placeholder(R.mipmap.ic_launcher)
.error(R.mipmap.pattern1)
.into(photo);
推荐答案
首先将 OkHttp 添加到应用模块的gradle构建文件中:
first add the OkHttp to the gradle build file of the app module :
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp:okhttp:2.4.0'
然后将此代码添加到您的课程中:
then add this code to your class :
Picasso.with(context).load("thumburl")
.networkPolicy(NetworkPolicy.OFFLINE)
.into(photo, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError() {
//Try for online if no data in cached or cached failed
Picasso.with(context)
.load("thumburl")
.placeholder(R.mipmap.ic_launcher)
.error(R.drawable.user_error)
.into(photo);
}
});
这篇关于wifi关闭时,如何使用毕加索图像加载器从缓存中显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文