2009-12-15 70 views
1

我正在使用listview來顯示數據,在listview內我正在每個listenite中使用圖像。Android listvitem AsyncTask圖像重疊

下面的方法從包裝類

public View getView(int position, View convertView, 
    ViewGroup parent) { // implementation } 

我下面這個教程 http://developer.android.com/guide/samples/ApiDemos/src/com/example/android/apis/view/List4.html

class DownloadImage extends AsyncTask<Void, Void, Drawable>{ 
     @Override 
     protected Drawable doInBackground(Void... params) { 
      return Util.getImageFromURL(imageURL); 
     } 

     @Override 
     protected void onPostExecute(Drawable d) { 
      getImageIcon().setImageDrawable(d); 
     } 

} 
new DownloadImage().execute(); 

以上代碼爲每臺的listItem懶圖片上傳調用。

問題是加載後的第一個圖像圖像彼此重疊....任何想法爲什麼發生這種情況?

+1

你能澄清你的意思是「圖像彼此重疊」嗎?你的意思是ListView不能正確繪製?還是所有的圖像都顯示爲單個列表項目? – 2009-12-15 09:17:01

+0

overalapping意味着一個項目圖像顯示在第二個listitem第二個監聽圖像消失並被任何其他listietm的圖像取代。 – 2009-12-15 09:55:19

回答

5

ListView行得到回收。您可能正在更新已回收的行,因此相關圖片不再有效。

在我cwac-thumbnail項目,我把URL的ImageView的標籤,然後確認ImageView仍然有標籤,當我去更新圖像。這樣,如果ImageView現在需要不同的圖像,我不會更改它以顯示錯誤的圖像。

+0

非常感謝gr8實現仍然在尋找緩存圖像。 – 2009-12-15 12:15:05