我试图将firebase存储中的图像放到我的应用程序的回收站视图中。与图像相关的文本即将出现但未显示图像。我不确定我哪里出错了。
我在我的ImageViewAdapter中使用Picasso来获取图像。
//这是我的imageViewAdapter
public class ImageAdapter extends RecyclerView.Adapter<ImageAdapter.ImageViewHolder> {
private Context context;
private List<Upload> mupload;
public ImageAdapter(Context context, List<Upload> uploads){
this.context = context;
this.mupload = uploads;
}
@NonNull
@Override
public ImageViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.winners, viewGroup, false);
return new ImageViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ImageViewHolder imageViewHolder, int i) {
Upload uploadCurrent = mupload.get(i);
imageViewHolder.month.setText(uploadCurrent.getMonth());
Picasso.get().load(uploadCurrent.getImageUri())
.fit().centerCrop().into(imageViewHolder.imageView);
}
@Override
public int getItemCount() {
return mupload.size();
}
public class ImageViewHolder extends RecyclerView.ViewHolder {
public TextView month;
public ImageView imageView;
public ImageViewHolder(@NonNull View itemView) {
super(itemView);
month = itemView.findViewById(R.id.tvMonth);
imageView = itemView.findViewById(R.id.ivWinner);
}
}
}
这是我显示图像的活动
public class ViewWinnerActivity extends AppCompatActivity {
RecyclerView recyclerView;
private ImageAdapter adapter;
private ProgressBar progressCircle;
DatabaseReference databaseReference;
List<Upload> uploads = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_winner);
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2);
recyclerView = findViewById(R.id.rv);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
progressCircle = findViewById(R.id.progress_circle);
databaseReference = FirebaseDatabase.getInstance().getReference("Uploads!");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()){
Upload upload = postSnapshot.getValue(Upload.class);
uploads.add(upload);
}
adapter = new ImageAdapter(ViewWinnerActivity.this, uploads);
recyclerView.setAdapter(adapter);
progressCircle.setVisibility(View.INVISIBLE);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(ViewWinnerActivity.this, databaseError.getMessage(),Toast.LENGTH_SHORT).show();
}
});
}