2

I am using a recycler-gridview to show few card items. It works properly, till I start scrolling down. All items gets mixed up. I know this i happening because of recycling. But how to handle this?

public void onBindViewHolder(ViewHolder viewHolder, int i) {




            if (listAll.get(i) != null) {
                viewHolder.ivPrimaryImage.setTag(listAll.get(i).getPostId());
                viewHolder.ivPrimaryImage.setImageBitmap(null); // Added for flickering issue
                viewHolder.tvTitle.setText(listAll.get(i).getTitle());
                postId = listAll.get(i).getPostId();
                Image image = new Image();
                image.setImg(viewHolder.ivPrimaryImage);
                viewHolder.holderId = i;
                String url = postId + "_1";

                Picasso.with(context).load(url).fit().into(viewHolder.ivPrimaryImage, new Callback() {
                    @Override
                    public void onSuccess() {

                    }

                    @Override
                    public void onError() {


                    }
                });
                viewHolder.itemView.setVisibility(View.VISIBLE);
            } else {

                viewHolder.itemView.setVisibility(View.GONE);
            }


    }

And my onCreateViewHolder looks like this.

@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
    View v = null;

    if( i == 1) {
        v = LayoutInflater.from(viewGroup.getContext())
                .inflate(R.layout.list_items_1, viewGroup, false);

    }else if(i == 0){
        v = LayoutInflater.from(viewGroup.getContext())
                .inflate(R.layout.headers, viewGroup, false);
    }else if(i == 2){
        v = LayoutInflater.from(viewGroup.getContext())
                .inflate(R.layout.headers, viewGroup, false);
    }

    ViewHolder viewHolder = new ViewHolder(v,i);

    return viewHolder;
}

And my Holder looks like this:

class ViewHolder extends RecyclerView.ViewHolder{

    TextView tvTitle;
    ImageView ivPrimaryImage;
    int holderId;
    TextView tvPostsMess ;

    public ViewHolder(View itemView, int i) {
        super(itemView);
        if(i == 0){
            tvPostsMess = (TextView)itemView.findViewById(R.id.tvPosts);
            holderId = 0;
        }else if( i == 1) {
            ivPrimaryImage = (ImageView) itemView.findViewById(R.id.ivPrimaryImageReview);
            tvTitle = (TextView) itemView.findViewById(R.id.tvTitleName);
            holderId = 1;
        }else if(i == 2){
            tvPostsMess = (TextView)itemView.findViewById(R.id.tvPosts);
            holderId = 2;
        }


    }
}

Please help!Somebody.

4

0 回答 0