Reputation: 75
I'm try to populate listview with all messages of all users of my Android app, but, I got it populate listview with only one user messages because I'm inserting messages information in database this form: Usuario > UID > Mensagem > Key creating with push > Data of mensagem. For better verification follows image of the database on firebase.
Can help me, please? Hugs.
Upvotes: 1
Views: 3476
Reputation: 126654
database.child("usuario").addValueEventListener(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot: dataSnapshot.getChildren()) {
for (DataSnapshot messageSnapshot: snapshot.child("mensagem").getChildren()) {
listView.add(messageSnapshot.child("textoMensagem").getValue().toString());
}
}
}
...
As you can see I add a ValueEventListener
to retrieve all children nodes of "usuario" and then loop through its children to get to your messages.
Tip: Think about (at least) posting your code/database structure etc. in English, it could make reading your question a lot easier.
Upvotes: 3