我正在使用recycler-gridview来显示几个卡片项目。 它工作正常,直到我开始向下滚动。所有项目都混淆了。 我知道这是因为回收而发生的事情。但是如何处理呢?
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);
}
}
我的onCreateViewHolder看起来像这样。
@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;
}
我的持有人看起来像这样:
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;
}
}
}
请帮忙!有人。