【发布时间】:2017-07-24 03:58:25
【问题描述】:
现在我基本上想做的是,首先是 Id:"cbn"。我已经用 push().setValue(gpsData) 推送了位置。 现在基于这个 id = "cbn",我想在 id = "cbn" 中添加新的纬度和经度strong>Location child 使用"push() 完全如上图所示。 到现在我的代码是:
mDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
if (busExists) {
// busId = "cbn"
mDatabase.child(busId).child("Location").push().setValue(gpsData);
}
我知道我不能将 busId 引用为子节点,但我如何访问该特定节点并将我的新数据推送到它。
有什么帮助吗?
对于新问题:
public class Users {
private String bus_id;
private HashMap<String, String> coord = new HashMap<>();
public Users() {
}
public String getBus_id() {
return bus_id;
}
public void setBus_id(String bus_id) {
this.bus_id = bus_id;
}
public HashMap<String, String> getCoord() {
return coord;
}
public void setCoord(HashMap<String, String> coord) {
this.coord = coord;
}
}
我是这样实现的:
mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
Users bus = new Users();
bus.setBus_id(ds.getValue(Users.class).getBus_id());
Log.e("bus id: ", bus.getBus_id()+""); // I got NULL
busList.add(bus.getBus_id());
arrayAdapter.notifyDataSetChanged();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
【问题讨论】:
标签: android firebase firebase-realtime-database