我正在运行我的应用程序并将一个新的子代添加到firebase中,您可以在线查看该子代的所有值,但是数据快照只会获取添加的新子代的第一个值。
我们尝试分别读取每个子值,但似乎数据快照甚至都不知道它们的存在。
public static void NotifyToTripList(final NotifyDataChange<List<Trip>> notifyDataChange) {
if (notifyDataChange != null) {
if (tripRefChildEventListener != null) {
notifyDataChange.onFailure(new Exception("first unNotify trip list"));
return;
}
tripList.clear();
tripRefChildEventListener = new ChildEventListener() {
@override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Trip t=new Trip();
t.setTripID(dataSnapshot.getKey());
if(dataSnapshot.child("DriverID").getValue()!=null) t.setDriverID(Long.parseLong(dataSnapshot.child("DriverID").getValue().toString()));
else t.setDriverID(0L);
t.setDestination(dataSnapshot.child("Destination").getValue().toString());
t.setCurrentLocation(dataSnapshot.child("CurrentLocation").getValue().toString());
t.setPassengerEmail(dataSnapshot.child("PassengerEmail").getValue().toString());
t.setPassengerNumber(dataSnapshot.child("PassengerNumber").getValue().toString());
t.setPassengerName(dataSnapshot.child("PassengerName").getValue().toString());
SimpleDateFormat format = new SimpleDateFormat("HH:mm");
tripList.add(t);
notifyDataChange.OnDataChanged(tripList);
}
}
}
主菜单中的代码:
FireBaseDataBase.NotifyToTripList(new FireBaseDataBase.NotifyDataChange<List<Trip>>() {
@Override
public void OnDataChanged(List<Trip> obj) {
FireBaseDataBase.tripList = obj;
}
@Override
public void onFailure(Exception exception) {
Toast.makeText(getBaseContext(), "error to get trips list\n" + exception.toString(), Toast.LENGTH_LONG).show();
}
});
这是普通的骑行数据快照的样子:
DataSnapshot {键= -LbbpVoPNgUDi-0eTDRY,值= {目的地= Mordehai A'liash 6,耶路撒冷,DriverID = 666666666,PassengerNumber = 0535291683,PassengerName = chana Gross,PassengerEmail = chanatriplet @ gmail.com,PickUpTime = 12: 20:00,CurrentLocation = Beit Ha-Defus 7,Jerusalem,TripStatus = DONE,DropOffTime = 21:06:04}}
这是新游乐设施数据快照的样子:
DataSnapshot {键= -Lbwu6QnvcvTZQuPsNEI,值= {CurrentLocation =药物,特拉维夫}}
这是数据库结构的样子: click here