我正在使用AsyncTask类为我的测验应用程序下载图像。这是类:使用附加参数调用AsyncTask类以检查显示图像的位置
public class DownloadImagesTask extends AsyncTask<ImageView, Void, Bitmap>{
ImageView imageView = null;
@Override
protected Bitmap doInBackground(ImageView... imageViews) {
this.imageView = imageViews[0];
return download_Image((String)imageView.getTag());
}
@Override
protected void onPostExecute(Bitmap result) {
// imageView.setImageBitmap(result);
downloaded_image = new BitmapDrawable(result);
//setting question image
question_view.setCompoundDrawablesWithIntrinsicBounds(null, null, null, downloaded_image);
}
private Bitmap download_Image(String url) {
//---------------------------------------------------
Bitmap bm = null;
try {
URL aURL = new URL(url);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
} catch (IOException e) {
Log.e("Hub","Error getting the image from server : " + e.getMessage().toString());
}
return bm;
//--------------------------------------------------
}
}
图像是越来越下载,我把图像我问题的TextView里面是这样的:
downloaded_image = new BitmapDrawable(result);
//setting question image
question_view.setCompoundDrawablesWithIntrinsicBounds(null, null, null, downloaded_image);
我给一个调用这个类从我的活动是这样的:
//image download
String imageURL = "http://cache.daylife.com/imageserve/074efG3gPV4oK/50x50.jpg";
image_downloadView.setTag(imageURL);
new DownloadImagesTask().execute(image_downloadView);
我想传递一些额外的参数,以确定我是否下载图像的问题或答案TextViews。
我该如何做到这一点?
在此先感谢!
P.S .:我有一个问题和四个选项在应用程序中的每一组问题。
ü得到什么问题,通过使用参数化类的构造多个参数DownloadImagesTask类? – 2013-03-25 10:18:22
而不是传入'ImageView'你应该传入一个自定义类型,它包含所有的参数类型,'...'表示你可以传入一个类型的数组.. – Josh 2013-03-25 10:31:02