2012-01-06 27 views
0

我試圖通過從列表視圖提取this 提示從網絡上延遲加載圖像唯一的問題是,當視圖被列表適配器回收時,它會導致列表中第一行加載錯誤的圖像。當我阻止適配器回收視圖時,它工作正常,但它不是執行listview最有效的方法。有沒有一種方法,我們可以在列表視圖中執行延遲加載的圖像,而視圖中的行被回收?如何在使用循環視圖的listview中進行延遲加載?

+0

你能否說出你的回收意味着什麼?你每次獲取圖像時都打電話給bitmap.recycle()嗎? – san 2012-01-06 09:10:02

+0

@Santhosh不,他的意思是一個視圖可以被另一個項目使用,通過'getView(...)'中的'convertView'參數' – rds 2012-01-06 10:49:00

+0

嘿接受幫助你解決問題的答案,或者如果你做出了不同的解決方案,就添加解決方案。分享與ppl .. – Shruti 2012-10-19 08:45:10

回答

0

我們可以避免錯誤的圖像通過在imageview的作爲標籤設置URL獲取加載。每次加載圖片時,我們都需要檢查正在加載圖片的網址。緩存的圖片加載之前負責下載和緩存圖像

//after image is downloaded, before loading it to the view 
    //cross check if this image-view is recycled if yes, 
    //getTag returns different URL than the one which is used to download image 
    String url = (String) m_imageViewRef.get().getTag(); 
    if(url != null && url.compareTo(m_url) == 0){           
    m_imageViewRef.get().setImageBitmap(result); 

使用同一個概念:請

if(referenceImageURL.length()!=0){ 
     //Store the image URL as Tag on the image view 
     holder.refImageView.setTag(referenceImageURL);  
     // use the image loader to download and load the image 
     //pass the image-view and the URL to image loader 
     imageManager.loadImage(referenceImageURL,holder.refImageView); 
}else{ 
    //URL is empty for this list-item 
    //set null on Tag and load default image here 
      holder.refImageView.setTag(null); 
    ... 
} 

的ImageManager視圖 - 用於圖像的圖像:看看下面

活動的解決方案image-view

+0

我想通了,但忘了把它發佈在這裏,這是我最終做的:)謝謝反正 – Nitin 2013-05-21 05:32:44