2015-11-06 64 views
1

我使用的是自定義列表視圖適配器一)視圖回收和B)視圖持有者對象數據。如何刪除從回收的列表視圖項

我也成功實現了一個異步圖像加載器類來加載位圖到列表視圖以獲得更流暢的滾動體驗。

現在這個問題看起來像回收利用,如果我錯了,那麼正確,但從視覺角度來看,它看起來像回收站顯示之前加載的位圖,然後加載新的位圖,舊圖像之間明顯的閃爍被新圖像替換。

我以前沒有注意到這種效果與文本視圖。這是回收問題嗎?當列表項目退出可視屏幕區域時,是否有辦法刮掉舊的位圖?

是的,我知道有第三方庫負責所有這些影響。如果我無法親自解決這個問題,那麼我會查看一個圖書館。

這是我的名單適配器

// Get the data item for this position 
    SongObject songObject = list.get(position); 

    // view lookup cache stored in tag 
    ViewHolder viewHolder; 

    // Check if an existing view is being reused, otherwise inflate the view 
    if (convertView == null) { 

     viewHolder = new ViewHolder(); 
     LayoutInflater inflater = LayoutInflater.from(getContext()); 

     convertView = inflater.inflate(R.layout.list_view_item, parent, false); 
     convertView.setTag(viewHolder); 

    } else { 

     viewHolder = (ViewHolder) convertView.getTag(); 
    } 

    // Set view holder references 

    viewHolder.album = (TextView) convertView.findViewById(R.id.album); 
    viewHolder.artist = (TextView) convertView.findViewById(R.id.artist); 
    viewHolder.title = (TextView) convertView.findViewById(R.id.title); 
    viewHolder.albumArt = (ImageView) convertView.findViewById(R.id.album_art); 
    viewHolder.duration = (TextView) convertView.findViewById(R.id.duration); 

    // Set values to referenced view objects 

    viewHolder.album.setText(songObject.album); 
    viewHolder.artist.setText(songObject.artist); 
    viewHolder.title.setText(songObject.title); 
    viewHolder.duration.setText(FormatTime(songObject.duration)); 

    // Load album art asynchronously for smoother scrolling experience 

    new ImageLoader(viewHolder.albumArt).execute(songObject.albumArtURI); 

    // Return the converted view 

    return convertView; 

回答

0

你使用recyclerView?你可以添加recyclerViewAdapter實現的代碼嗎?

onBindViewHolder是一個地方,您應該'調整'您以前使用(或未使用)的viewHolder,然後將其提供給用戶