我有一个recyclerview来显示图像,问题是当我滚动到顶部时,一些图像消失了。有时它也会错过一些图像......
CARDADAPTER:
public class CardAdapter extends RecyclerView.Adapter<CardAdapter.ViewHolder> {
//Imageloader to load image
private ImageLoader imageLoader;
private final Context context;
//List to store all posts
List<Posts> Posts;
//Constructor of this class
public CardAdapter(List<Posts> Post, Context context){
super();
//Getting all
this.Posts = Post;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.posts_list, parent, false);
ViewHolder viewHolder = new ViewHolder(v);
return viewHolder;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
//Getting the particular item from the list
Posts post = Posts.get(position);
//Loading image from url
imageLoader = CustomVolleyRequest.getInstance(context).getImageLoader();
//Showing data on the views
holder.imageView.setImageUrl(post.getImageUrl(), imageLoader);
holder.textViewName.setText(post.getName());
holder.textViewPublisher.setText(post.getPublisher());
}
@Override
public int getItemCount() {
return Posts.size();
}
class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
//Views
public NetworkImageView imageView;
public TextView textViewName;
public TextView textViewPublisher;
//Initializing Views
public ViewHolder(View itemView) {
super(itemView);
imageView = (NetworkImageView) itemView.findViewById(R.id.imageViewHero);
textViewName = (TextView) itemView.findViewById(R.id.textViewName);
textViewPublisher = (TextView) itemView.findViewById(R.id.textViewPublisher);
textViewName.setClickable(true);
textViewName.setOnClickListener(this);
}
@Override
public void onClick(View v) {
final Intent intent;
intent = new Intent(context, Profile.class);
intent.putExtra("user", textViewName.getText().toString());
context.startActivity(intent);
}
}
}
为什么我的图片会从recyclerview中消失?我该怎么办?