我尝试从Firebase实时数据库中检索图像,并使用Picasso将这些图像作为图像滑块(幻灯片)显示回来。但是,这只允许我检索存储在Firebase中的最后一个图像。非常感谢您的任何帮助!
enter code here
public void update(View view) {
DatabaseReference mDatabaseRef = FirebaseDatabase.getInstance().getReference().child("uploads");
mDatabaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
// TODO Auto-generated method stub
if(snapshot.exists()) {
for(DataSnapshot s:snapshot.getChildren()) {
//For Image1
StringBuilder img1=new StringBuilder();
Upload t = s.getValue(Upload.class);
img1.append(t.getImageUrl());
image1.setText(img1.toString());
String image1url=image1.getText().toString();
Picasso.get().load(image1url).into(imageView1);
StringBuilder img2=new StringBuilder();
Upload a = s.getValue(Upload.class);
img2.append(a.getImageUrl());
image2.setText(img1.toString());
String image2url=image2.getText().toString();
Picasso.get().load(image2url).into(imageView2);
}
这是我的数据库结构
Firebase-root
|
--- uploads
|
--- LZ6KO5TaHGaIthbhbnj
| |
--- imageUrl1: "https://..."
| |
--- name: "firstpic"
|
--- LZ6NKm-zZg5EW1hvhvh
|
--- imageUrl2: "https://..."
|
--- name: "secondpic"
LZ6KO5TaHGaIthbhbnj
显示在第一行的TextVIew/ImageView中,第二个LZ6NKm-zZg5EW1hvhvh
显示在第二行的TextVIew/ImageView中,对吗?只有两项? - Alex Mamo