从Firebase检索所有用户ID的数据 [英] Retrieve data of all user id from firebase

查看:59
本文介绍了从Firebase检索所有用户ID的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用我的Android应用程序的所有用户的所有消息填充listview,但是,我只用一条用户消息填充listview,因为我是在数据库中以这种形式插入消息信息的: Usuario> UID> Mensagem>通过推键创建> Mensagem的数据. 为了更好地进行验证,请遵循Firebase上的数据库映像.

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.

能帮我吗? 拥抱.

推荐答案

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());
             }
         }
    }

    ...

如您所见,我添加了一个ValueEventListener来检索"usuario"的所有子节点,然后循环浏览其子节点以获取您的消息.

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.

提示:考虑(至少)以英语发布您的代码/数据库结构等,这可以使您阅读问题变得更加容易.

这篇关于从Firebase检索所有用户ID的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆