1

我正在使用 Recycler View 创建项目列表,并且我在列表中获得了重复的项目。我已将 30 大小的列表传递给 Recycler View Adapter。创建的列表有 30 个项目,但只有 3 个唯一项目,所有其他都是 3 个唯一项目的重复。我无法找到错误。

public class CollectionAdapter extends RecyclerView.Adapter<CollectionAdapter.CollectionViewHolder> {
private List<CollectionDataTypeModel> mDataSet = new ArrayList<CollectionDataTypeModel>();
private Activity mActivity;
private String mType;


public CollectionAdapter(List<CollectionDataTypeModel> mDataSet, Activity activity, String type) {
    this.mActivity = activity;
    this.mDataSet = mDataSet;
    this.mType = type;

}

@Override
public CollectionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.collection_cardview_layout, parent, false);
    CollectionViewHolder vh = new CollectionViewHolder(v);
    return vh;
}

@Override
public void onBindViewHolder(final CollectionViewHolder holder, int position) {


    final CollectionDataTypeModel collectionData = mDataSet.get(position);
    Log.d("Colelction Adapter","name : "+collectionData.getCollectionName());
    holder.titleText.setText(collectionData.getCollectionName()+"");
    holder.secondaryText.setText(collectionData.getPoiCount()+" attractions");
    if (mType.equalsIgnoreCase("Collection")) {
        Glide.with(mActivity).load(R.drawable.aman).asBitmap().centerCrop().into(new BitmapImageViewTarget(holder.profileImage) {
            @Override
            protected void setResource(Bitmap resource) {
                RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(mActivity.getResources(), resource);
                circularBitmapDrawable.setCircular(true);
                holder.profileImage.setImageDrawable(circularBitmapDrawable);
            }
        });
    } else if (mType.equalsIgnoreCase("Destination")) {
        holder.profileImageRipple.setVisibility(View.GONE);
    } else if (mType.equalsIgnoreCase("Download")) {
        holder.profileImageRipple.setVisibility(View.GONE);
        holder.viewIcon.setImageResource(R.drawable.clear_icon);
        holder.viewCount.setVisibility(View.INVISIBLE);
    }
     //    holder.collectionImage.setImageResource(R.drawable.goldentemple);
        Glide.with(mActivity).load(collectionData.getCollectionImage()).into(holder.collectionImage);

    holder.likeCount.setText(Integer.toString(collectionData.getLikeCount()));
    holder.viewCount.setText(Integer.toString(collectionData.getViewCount()));

    holder.likeIconRipple.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
        @Override
        public void onComplete(RippleView rippleView) {
           // if(holder.likeIcon.getDrawable()==mActivity.getDrawable(R.drawable.like_icon))
           {
                holder.likeIcon.setImageResource(R.drawable.like_fill_icon);
            }
           // else
            {
             //   holder.likeIcon.setImageResource(R.drawable.like_icon);
            }
        }
    });
    holder.collectionImageRipple.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
        @Override
        public void onComplete(RippleView rippleView) {
            EventBus.getDefault().post(new CollectionMessageEvent(collectionData));
        }
    });


}

@Override
public int getItemCount() {
    return mDataSet.size();
}

@Override
public long getItemId(int position) {
    return super.getItemId(position);
}

public static class CollectionViewHolder extends RecyclerView.ViewHolder {
    TextView titleText;
    ImageView collectionImage;
    TextView secondaryText;
    TextView likeCount;
    TextView viewCount;
    ImageView profileImage;
    ImageView viewIcon;
    RippleView collectionImageRipple;
    RippleView profileImageRipple;
    RippleView likeIconRipple;
    ImageView likeIcon;


    public CollectionViewHolder(View itemView) {
        super(itemView);
        // View bottombar =  findById(itemView,R.id.bottomBar);

        collectionImage = findById(itemView, R.id.collection_image);
        collectionImageRipple = findById(itemView, R.id.collection_image_ripple);
        profileImage = findById(itemView, R.id.profileimage);
        profileImageRipple = findById(itemView, R.id.profileimage_ripple);
        titleText = findById(itemView, R.id.title_text);
        secondaryText = findById(itemView, R.id.secondary_text);
        likeCount = findById(itemView, R.id.like_count);
        likeIcon = findById(itemView, R.id.like_icon);
        likeIconRipple = findById(itemView, R.id.like_icon_ripple);
        viewCount = findById(itemView, R.id.view_count);
        viewIcon = findById(itemView, R.id.view_icon);
    }


}


}
4

0 回答 0