以下是我的代码。我正在尝试在活动负载上加载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);
}
}