我开发了一个列表视图,列表视图显示图像和文本.1必须下载图像和文本形式的网络服务,然后必须显示,因为它需要更多的时间,所以我们认为第一次绑定文本在列表视图和使用AsyncTask
,一旦图像下载图像将在活动的背景中显示在列表视图中。但我无法做到这一点,我已经做了一些编码,它下载所有图像,然后绑定图像和文本(在这种情况下我们需要下载image.So后前startDownload图像和2月1日两次绑定列表视图,如果任何有一些想法,请给我建议。文本和图像的自定义列表视图
代码
public class LoadImg extends AsyncTask<String, Void, Bitmap> {
Context context;
String img;
InputStream is = null;
Bitmap bitmap = null;
public LoadImg(Context context, String img) {
// TODO Auto-generated constructor stub
this.context = context;
this.img = img;
}
@Override
protected Bitmap doInBackground(String... params) {
// TODO Auto-generated method stub
Bitmap bitmap = downImg();
System.out
.println("Value of bitmap====================================="
+ bitmap);
return bitmap;
}
private Bitmap downImg() {
// TODO Auto-generated method stub
Bitmap bitmap = null;
if (img == null) {
bitmap = null;
} else {
URL url = null;
try {
url = new URL(img);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
URLConnection connection = null;
try {
connection = url.openConnection();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
is = connection.getInputStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
bitmap = BitmapFactory.decodeStream(is);
System.out.println("TV Image===" + bitmap);
}
return bitmap;
}
}
你要做的惰性加载... –
感谢穿心莲内酯,u能告诉我在深怎么办这... – Dilip
我认为用户已经在他的评论中提供了他的答案中的链接。去那个链接并且检查Fedor的答案。这是最好的策略和非常简单的实施。 –