我从http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html获得了图像下载代码,令我感到困惑的是,他是如何从下载()中获得图像视图的视图,而没有从ImageDownloader获得返回值?
public class ImageAdapter extends BaseAdapter {
...
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
view = new ImageView(parent.getContext());
view.setPadding(6, 6, 6, 6);
}
imageDownloader.download(URLS[position], (ImageView) view);
return view;
}
..
public class ImageDownloader {
...
private void forceDownload(String url, ImageView imageView) {
....
case CORRECT:
task = new BitmapDownloaderTask(imageView);
DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
imageView.setImageDrawable(downloadedDrawable);
imageView.setMinimumHeight(156);
task.execute(url);
发布于 2014-04-16 14:08:32
如果您查看BitmapDownloadTask
类内部,就会看到imageView.setImageBitmap(bitmap);
on OnPostExecute
方法,该方法一旦下载就设置位图。
注意,一旦下载了映像,就会调用OnPostExecute
方法。
编辑:当您调用下载时,您将ImageView
对象的引用作为参数传递。因此,当该方法进行诸如设置图像之类的更改时,它将对传递的对象进行相同的操作。
对象在java中作为引用传递。因此,两个ImageView
都引用同一个对象。
希望能帮上忙!
发布于 2014-04-17 00:57:54
我对java做了些搜索。
http://www.yoda.arachsys.com/java/passing.html
看起来,imageview是作为对象传入的,因此,它作为引用传入。谢谢你的帮助。
https://stackoverflow.com/questions/23111498
复制相似问题