我发现imageView中未显示FirebaseRecyclerAdapter中的某些图像(存储在FireStorage中)。 并且通过上下滚动显示的图像不在手机屏幕上时,它们也消失了。
然后当我重复滚动屏幕时,有时会再次显示它们。
@Override
protected void onStart() {
super.onStart();
final Query DBquery = FirebaseDatabase.getInstance().getReference().child("post").orderByChild("count").limitToFirst(10);
final FirebaseRecyclerAdapter<Post, PostViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Post, PostViewHolder>(
Post.class,
R.layout.post_row,
PostViewHolder.class,
DBquery
) {
@Override
protected void populateViewHolder(PostViewHolder viewHolder, Post model, int position) {
viewHolder.setTitle(model.getTitle());
viewHolder.setDesc(model.getDesc());
viewHolder.setImage(getApplicationContext(), model.getImage());
viewHolder.setDate(model.getDate());
viewHolder.init(position, model);
}
@Override
public void onBindViewHolder(PostViewHolder viewHolder, int position) {
super.onBindViewHolder(viewHolder, position);
}
};
mPostList.setAdapter(firebaseRecyclerAdapter);
}
,然后检查图像是否为空。 当它们不显示时,它们的值为空。
public void setImage(Context ctx, String image){
ImageView post_image = mView.findViewById(R.id.post_image);
if (image == null){
post_image.setVisibility(View.GONE);
}else{
Glide.with(ctx)
.load(image)
.into(post_image);
}
}
jhhjh