-4
My Database Image from Firebase從火力檢索所有值,並把它變成一個TextView
我想找回這兩個DOSA和Dosa2,並把它變成一個TextView。 下面是我試過的代碼,但我只能檢索Dosa2。
mMessagesDatabaseReference = mFirebaseDatabase.getReference("messages");
// Attach a listener to read the data at our posts reference
mMessagesDatabaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) {
Food food = postSnapshot.getValue(Food.class);
foodnameTextView.setText(food.getFoodname()+"\n");
}}
@Override
public void onCancelled(DatabaseError databaseError) {
System.out.println("The read failed: " + databaseError.getCode());
}
});
非常感謝,這是多麼愚蠢的我犯的錯 –