1
votes

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. Structure of database firebase

Can help me, please? Hugs.

1
Getting ALL the data from the database is a bad practice. - tim4dev
Yes, but I used a condition to retrieve, thanks. - D.Almeida

1 Answers

3
votes
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.