2013-12-17 32 views
0

我使用Volley庫下載圖像。我想在加載圖像後更改TextView的文本。就像在文本加載之前一樣。並在圖像加載後它應該改變爲加載。Android排球:執行任務imageload

NetworkImageView image = (NetworkImageView)findViewById(R.id.imageView1); 
image.setDefaultImageResId(R.drawable.def); 
image.setImageUrl(url, ImageUtil.getImageLoader(getApplicationContext())); 

如何在圖像完全加載時偵聽或調用函數?

+0

你試過繼承'NetworkImageView'並添加接口圖像loades? – user2558461

+0

什麼是imageView1?定義在哪裏? –

回答

1

您可以嘗試如下的代碼片斷..

ImageView image = ImageView.class.cast(layout.findViewById(R.id...)); 
    String url = "..."; // URL of the image 

    mImageLoader.get(url, new ImageListener() { 

       public void onErrorResponse(VolleyError arg0) { 
        image.setImageResource(R.drawable.icon_error); // set an error image if the download fails 
       } 

       public void onResponse(ImageContainer response, boolean arg1) { 
        if (response.getBitmap() != null) { 
         image.startAnimation(AnimationUtils.loadAnimation(container.getContext(), android.R.anim.fade_in)); 
         image.setImageBitmap(response.getBitmap()); 
        } else 
         image.setImageResource(R.drawable.icon_loading); // set the loading image while the download is in progress 
       } 
      }); 

可以如下創建mImageLoader實例來實現緩存

mRequestQueue = Volley.newRequestQueue(context); 
mImageLoader = new ImageLoader(mRequestQueue, new ImageLoader.ImageCache() { 
    private final LruCache<String, Bitmap> mCache = new LruCache<String, Bitmap>(10); 
    public void putBitmap(String url, Bitmap bitmap) { 
     mCache.put(url, bitmap); 
    } 
    public Bitmap getBitmap(String url) { 
     return mCache.get(url); 
    } 
});' 
+0

它也會緩存圖片嗎?我也需要緩存圖片 –

+0

我編輯了我的答案,以便您可以實現緩存。 –

相關問題