2012-01-03 29 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()來完成圖像加載時需要做的任何事情。

相關問題