我正在使用 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。
我如何实现这一目标?
提前致谢!
PS:对于每组问题,我在申请中都有一个问题和四个选项。