![](/img/trans.png)
[英]Java, Android studio, Firebase database how to add data to realtime database
[英]How to add new data to Firebase database in android?
这取决于您存储数据的方式。 如果你有一个类在它的对象中包含你所有的值,那么你可以使用这样的代码来做到这一点:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("userTable");
// where User is your class and user is it's object with the values you need to update
ref.child(user.getNumber()).setValue(user);
如果您没有这样的类并且您需要设置这些值,那么您必须对数据库的每个节点单独进行设置,代码如下:
DatabaseReference refNew = FirebaseDatabase.getInstance().getReference().child("userTable").child(i);
// where i is the variable which you have to keep count of your users
ref.child("Age").setValue(age);
ref.child("Company").setValue(company); // and so on
// age, company are variable with values you want to store
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.