适配器设置图片
来源:互联网 发布:java 图片验证码 开源 编辑:程序博客网 时间:2024/06/08 10:57
AsyncTask<Void, Void, Bitmap> asyncTask = new AsyncTask<Void, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(Void... voids) {
try {
URL url = new URL(picUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//设置
connection.setRequestMethod("GET");
connection.setReadTimeout(5000);
connection.setConnectTimeout(5000);
//获取
int responseCode = connection.getResponseCode();
if (responseCode == 200){
InputStream inputStream = connection.getInputStream();
//转成bitmap
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
return bitmap;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
/*if (imageView.getTag().equals(picUrl)){
//设置
imageView.setImageBitmap(bitmap);
}*/
imageCallBack.setSuccessImage(bitmap,imageView);
}
};
asyncTask.execute();
}
//接口回调
public interface ImageCallBack {
public void setSuccessImage(Bitmap bitmap, ImageView imageView);
}
//适配器的
//显示图片....
/**
* 为什么图片会产生错位 闪烁?????图片是异步加载+复用的优化的原因
*
* 1.imageView要跟自己的url路径匹配起来
*/
holder.imageView.setTag(list.get(i).getPicUrl());
//3.设置默认显示的图片
holder.imageView.setImageResource(R.mipmap.ic_launcher);
//2.在这个位置能区分出来imageView是当前的控件...借助接口回调的形式把异步获取的图片传递过来
new ImageHelper().dispalyImage(list.get(i).getPicUrl(),holder.imageView, new ImageCallBack() {
@Override
public void setSuccessImage(Bitmap bitmap, ImageView imageView) {
if (imageView.getTag().equals(list.get(i).getPicUrl())){
//
imageView.setImageBitmap(bitmap);
}
}
});
- 适配器设置图片
- 适配器设置图片
- 图片适配器
- 设置适配器
- 处理图片适配器代码
- Spinner 设置适配器, adapter
- 图片三级缓存仅适配器
- 适配器中加载耗时图片的处理
- 仿微信的图片和视频选择适配器
- HttpURLConnection一个适配器加载图片的类
- 图片的异步加载和适配器
- android listview 三种适配器设置
- BaseAdapter 自定义适配器设置网格布局
- AutoCompleteTextView练习,重点为适配器设置
- 引导页面滑动ViewPager(设置ViewPager适配器)
- DataBinding设置一个万能的RecyclreView适配器
- 适配器
- 适配器
- 博客已经转移
- zookeeper命令行操作
- [learning materials] tone and phonetics
- lua脚本学习13 迭代器
- Spring AOP (一)
- 适配器设置图片
- 土圭垚㙓数学课(四)空间变换
- Android studio下使用ndk-stack定位crash
- Git客户端下载及安装
- 单一职责原则
- Centos7 error: Failed to initialize NSS library
- 三户信息
- 技术文章收藏
- 源码圈 300 胖友的书单整理(最后更新时间:2017.09.22)