我正在尝试使用Glide从Firebase检索图像到列表视图。我收到错误消息“您必须传递非null视图”。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.imagetarget);
img = new Image();
listView = findViewById(R.id.imagegrid);
target = findViewById(R.id.target);
database = FirebaseDatabase.getInstance();
ref = database.getReference("Image");
arrayList = new ArrayList<>();
adapter = new ArrayAdapter<String>(this, R.layout.getimage, R.id.name, arrayList);
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot ds: dataSnapshot.getChildren()){
img = ds.getValue(Image.class);
final String url = "https://firebasestorage.googleapis.com/v0/b/arapp-d03cb.appspot.com/o/bacteria-1-450x285.jpg?alt=media&token=db1e3e3d-f56d-417d-b358-c10ce6f9ae37";
arrayList.add(img.getName() + "\n" + img.getDescription() + "\n" + Glide.with(getApplicationContext()).load(url).into(target));
}
listView.setAdapter(adapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
我希望图像会与文本一起加载到列表视图中。除了此方法外,还有其他方法可以做到这一点。