2012-01-03 67 views
0
/** 
* Defines an interface for a callback that will handle 
* responses from the thread loader when an image is done 
* being loaded. 
*/ 
public interface ImageLoadedListener { 
    public void imageLoaded(Bitmap imageBitmap); 
} 

然后某处空函数,什么是使用,因为它的代码是一个空存根

// If in the cache, return that copy and be done 
       if(Cache.containsKey(item.url.toString()) && Cache.get(item.url.toString()) != null) { 
        // Use a handler to get back onto the UI thread for the update 
        handler.post(new Runnable() { 
         public void run() { 
          if(item.listener != null) { 
           // NB: There's a potential race condition here where the cache item could get 
           //  garbage collected between when we post the runnable and it's executed. 
           //  Ideally we would re-run the network load or something. 
           SoftReference<Bitmap> ref = Cache.get(item.url.toString()); 
           if(ref != null) { 
            item.listener.imageLoaded(ref.get()); 
           } 
          } 
         } 
        }); 
       } else { 
        final Bitmap bmp = readBitmapFromNetwork(item.url); 
        if(bmp != null) { 
         Cache.put(item.url.toString(), new SoftReference<Bitmap>(bmp)); 

         // Use a handler to get back onto the UI thread for the update 
         handler.post(new Runnable() { 
          public void run() { 
           if(item.listener != null) { 
            item.listener.imageLoaded(bmp); 
           } 
          } 
         }); 
        } 

       } 

我的问题是imageLoaded(位图imageBitmap)是空函数它并不做任何事情,除了提供回电话。所以,item.listener.imageLoaded(ref.get());那有什么意义?或者它导致什么?因为imageLoaded是一个空的存根函数。 Samething with item.listener.imageLoaded(bmp);这似乎导致无处。

回答

2

ImageLoadedListener是一个接口。该接口的实现可以提供自己的实现imageLoaded()来完成图像加载时需要做的任何事情。

相关问题