加载的活动不会加载Firebase数据

时间:2017-09-13 17:35:05

标签: android firebase firebase-realtime-database

以下是我的代码。我正在尝试在活动负载上加载firebase数据。问题是目前onchildadded是不起作用,但改变的孩子是完美的。我是firebase的新手,所以我无法弄清楚问题。请帮我修理一下。先感谢您。 :)

mydatabase = FirebaseDatabase.getInstance().getReference().child(roomname); 
  mydatabase.addChildEventListener(new ChildEventListener() {
                    @Override
                    public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                        append_chat(dataSnapshot);
                    }

                @Override
                public void onChildChanged(DataSnapshot dataSnapshot, String s) {
                    append_chat(dataSnapshot);
                }

                @Override
                public void onChildRemoved(DataSnapshot dataSnapshot) {

                }

                @Override
                public void onChildMoved(DataSnapshot dataSnapshot, String s) {

                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });

String data_user_id,data_user_name,data_msg;
    private void append_chat(DataSnapshot dataSnapshot)
    {
        Iterator i = dataSnapshot.getChildren().iterator();
        while (i.hasNext())
        {
            data_user_id = (String) ((DataSnapshot)i.next()).getValue();
            data_user_name = (String) ((DataSnapshot)i.next()).getValue();
            data_msg = (String) ((DataSnapshot)i.next()).getValue();
            mytext.append(data_msg);
        }
    }

0 个答案:

没有答案