Retrieve data of all user id from firebase

后端 未结 1 442
借酒劲吻你
借酒劲吻你 2021-01-25 03:47

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 infor

相关标签:
1条回答
  • 2021-01-25 04:44
    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.

    0 讨论(0)
提交回复
热议问题