Android - RecyclerView加载的数据很少

时间:2017-05-24 03:39:25

标签: android android-recyclerview adapter

H,我正在开发一个显示列表中所有视频的应用程序。将列表加载到RecyclerView时出现问题,列表中的所有项目在1,2秒内都很小,然后填写所有数据,如下图所示:

  • 列表项

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);
  }
}

1 个答案:

答案 0 :(得分:2)

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

此行代码将从服务器获取图像,并将延迟到图像成功。你应该为Picasso设置占位符图像。

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