2017-05-24 62 views
0

H,我正在開發一個應用程序,該應用程序顯示列表中的所有視頻。裝貨清單到RecyclerView當我的問題,在列表中的所有項目是微小的1,2秒鐘,然後填寫所有資料,如下面的圖像:
Android - RecyclerView正在緩慢加載小數據

  • 列表項

First, it display almost item but it's small and not fill data

  • 1,2秒後:

enter image description here

  • 這是我的適配器:
@Override 
public void onBindViewHolder(final MostPopularByCountryAdapter.ViewHolder holder, final int position) { 
    // fetch data to UI 
    holder.order.setText(String.valueOf(position + 1)); 
    holder.name.setText(mListVideo.get(position).getTitle()); 
    Picasso.with(mContext).load(mListVideo.get(position).getThumbnailsHigh().getUrl()).into(holder.videoThumbnail); 
    holder.duration.setText(UtilitySupport.convertDuration(mListVideo.get(position).getDuration().trim())); 

    boolean isFavour = dataPreferences.getBookmarkVideo(mListVideo.get(position).getVideoId()); 
    mListVideo.get(position).setFavourite(isFavour); 
    final VideoStorageEntity storageEntity = new VideoStorageEntity(); 
    storageEntity.setVideoId(mListVideo.get(position).getVideoId()); 
    storageEntity.setFavourite(isFavour); 
    storageEntity.setThumbnailsHighUrl(mListVideo.get(position).getThumbnailsHigh().getUrl()); 
    storageEntity.setTitle(mListVideo.get(position).getTitle()); 

    // setting 3 button action // 
    // favourite event 
    holder.viewLike.setOnStateChangeListener(true, mListVideo.get(position).isFavourite(), new OnStateChangeListener() { 
     @Override 
     public void onSelectedChange(boolean isSelected) { 
      if (isSelected) { 
       holder.isLike.setImageResource(R.drawable.ic_action_love_press); 
       dataPreferences.saveBookmarkVideo(storageEntity); 
      } else { 
       holder.isLike.setImageResource(R.drawable.ic_action_love_white); 
       dataPreferences.removeBookmarkVideo(storageEntity); 
      } 
      mListVideo.get(position).setFavourite(isSelected); 
     } 
    }); 
    if (mListVideo.get(position).isFavourite()) { 
     holder.isLike.setImageResource(R.drawable.ic_action_love_press); 
    } else { 
     holder.isLike.setImageResource(R.drawable.ic_action_love_white); 
    } 
} 
+0

mListVideo中的數據是來自服務器嗎? –

+0

您正在重複加載視頻數據,幾乎肯定是從服務器上加載的。是的,那永遠不會工作。 –

+0

我忘了添加佔位符。路易斯Nguyen建議我。謝謝你 –

回答

2
Picasso.with(mContext).load(mListVideo.get(position).getThumbnailsHigh().getUrl()).into(holder.videoThumbnail); 

這行代碼會從服務器獲取圖像,並會延遲,直到圖像獲取成功。您應該爲畢加索設置地點持有人圖像。

Picasso.with(mContext).load(mListVideo.get(position).getThumbnailsHigh().getUrl()).placeholder(R.drawable.your_resource).into(holder.videoThumbnail); 
+0

謝謝,這似乎工作 –