I\'m a newbie programmer an I\'m making an android program that displays an image on ImageView from a given url. My problem is how do you use this on the AsyncTask?
Thes
Here is the code for the Aynctask implementation Make your drawable object as global in Aynctask class.
Class MyDownloader extends AsyncTask{
Drawable drawable;
@Override
public String doInBackground(Void... args){
drawable = LoadImageFromWeb("http://www.pagasa.dost.gov.ph/wb/sat_images/satellite.gif");
return null; // here you can pass any string on response as on error or on success
}
public void onPostExecute(String result){
if(drawable!=null){
imgView.setImageDrawable(drawable);
}
}
}
now create object of this class and execute it
private void satellite() {
// TODO Auto-generated method stub
ImageView imgView =(ImageView)findViewById(R.id.satellite);
new MyDownloader.execute();
}
Here is good example link for caching the image check out this link and example
https://github.com/novoda/ImageLoader