【发布时间】:2014-03-24 19:12:20
【问题描述】:
我深入查看了http://developer.android.com/training/displaying-bitmaps/process-bitmap.html 此处的文档,并使用本指南http://android-developers.blogspot.in/2010/07/multithreading-for-performance.html 创建了一个处理异步任务并发的 ImageLoader。
我的代码几乎相同,特别是我下面的代码完全相同:
private static BitmapDownloaderTask getBitmapDownloaderTask(ImageView imageView) {
if (imageView != null) {
Drawable drawable = imageView.getDrawable();
if (drawable instanceof DownloadedDrawable) {
DownloadedDrawable downloadedDrawable = (DownloadedDrawable)drawable;
return downloadedDrawable.getBitmapDownloaderTask();
}
}
return null;
}
问题是条件
DownloadedDrawable 的可绘制实例
从未经过验证。一切看起来都不错,但drawable 似乎不是我的DownloadedDrawable 类的一个实例,我不知道为什么。你能帮帮我吗?
编辑:我发现这与引用有关。事实上,imageView.getDrawable() 返回一个具有 BitmapDrawable 引用的对象
android.graphics.drawable.BitmapDrawable@yyyyyyyy
如果我尝试将其转换为 DownloadedDrawable 对象(我的自定义子类的实例)或在其上使用 instanceof 运算符,则会出现错误,因为该对象是通过 DowanloadedDrawable 引用访问的
my_package.image_loader.DownloadedDrawable@xxxxxxxx
如何解决这个问题?
【问题讨论】:
-
drawable 是非空的吗?
-
是的。我检查了所有参考资料,一切似乎都分配得很好。
标签: android image reference android-asynctask