我想在 Recyclerview 中显示我从 firebase 存储上传的图像。
这是我的 ImagesShowingNotices.java 类
private RecyclerView mRecyclerView;
private ImageAdapter mAdapter;
private ProgressBar mProgressCircle;
private DatabaseReference mDatabaseRef;
private List<Uplaodfiles> mUploads;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_showing_notices);
mRecyclerView = findViewById(R.id.recyclerviewitems);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mProgressCircle = findViewById(R.id.progress_circle);
mUploads = new ArrayList<>();
mDatabaseRef = FirebaseDatabase.getInstance().getReference("Uploads");
mDatabaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
Uplaodfiles upload = postSnapshot.getValue(Uplaodfiles.class);
mUploads.add(upload);
}
mAdapter = new ImageAdapter(ImageShowingNotices.this, mUploads);
mRecyclerView.setAdapter(mAdapter);
mProgressCircle.setVisibility(View.INVISIBLE);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(ImageShowingNotices.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
mProgressCircle.setVisibility(View.INVISIBLE);
}
});
}
@Override
protected void onStart() {
super.onStart();
}
这是我的 UploadFiles.java 类
public Uplaodfiles() {
//empty constructor needed
}
public Uplaodfiles(String name, String imageUrl) {
if (name.trim().equals("")) {
name = "No Name";
}
mName = name;
mImageUrl = imageUrl;
}
public String getName() {
return mName;
}
public void setName(String name) {
mName = name;
}
Logcat 显示“未连接适配器;跳过布局”。我已经尝试了 StackOverflow 上发布的有关此问题的其他解决方案,但没有任何效果。请帮助我摆脱这种困境。
富国沪深
HUX布斯
相关分类