我開發了一個列表視圖,列表視圖顯示圖像和文本.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的答案。這是最好的策略和非常簡單的實施。 –