【发布时间】:2012-11-27 15:25:50
【问题描述】:
我正在使用 Gilles Debunne 在Multithreading For Performance 中描述的 ImageDownloader,我想做一个简单的扩展。
我想为每个尚未下载的列表项添加一个不确定的ProgressBar。我现在主要是通过调用来设置它:
progressBar.setVisibility(View.VISIBLE); // in the AsyncTask preExecute()
progressBar.setVisibility(View.INVISIBLE); // in the AsyncTask postExecute()
具体来说,只要在 postExecute() 中设置 imageView 的位图,我就会将进度条标记为不可见……就像这样:
if (this == bitmapDownloaderTask) {
imageView.setImageBitmap(bitmap);
progBar.setVisibility(View.INVISIBLE);
}
但我一直无法找到正确的测试来使preExecute() 中的进度条可见。我尝试了各种组合:
if (imageView == null)
if (imageView.getDrawingCache() == null)
if (downloadedDrawable == null)
if (downloadedDrawable.getColor() == Color.BLACK)
有人对如何使这项工作提出建议吗?那就是:对于这段代码,确定给定位图是否设置的正确测试是什么?谢谢!
【问题讨论】:
标签: android caching android-asynctask android-progressbar