I have developed a listview,listview displaying image and text.1st have to download image and text form web-service then have to display because it takes more time so we thought 1st bind text in listview and use AsyncTask
and as soon as image download image will be shown in the listview in the background of activity.But i'm unable to do that i have done some coding and it download all image and then bind both image and text(in this case we need to bind listview two times 1st before startDownload image and 2nd after download image.So if any has some idea please suggest me.
Code
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;
}
}