Reputation: 483
I am able to update data like address and description by doing the following:
FirebaseUser current_user = FirebaseAuth.getInstance().getCurrentUser();
String uid = current_user.getUid();
mDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(uid);//.getReference points to root.
HashMap<String,Object> usermap = new HashMap<>();
usermap.put("name",name);
usermap.put("description",description);
usermap.put("address",address);
mDatabase.updateChildren(usermap);
But how do I add Week? Week has five children which are the days.Within each child, I would like an array of integer or string characters. I tried the same way as above but it does not seem to be working. The above method only works for key:value.
Upvotes: 0
Views: 46
Reputation: 598728
The week is a nested Map
, so:
FirebaseUser current_user = FirebaseAuth.getInstance().getCurrentUser();
String uid = current_user.getUid();
mDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(uid);//.getReference points to root.
HashMap<String,Object> usermap = new HashMap<>();
usermap.put("name",name);
usermap.put("description",description);
usermap.put("address",address);
Map<String,String> week = new HashMap<>();
week.put("Monday", "1,1,1,1,1,1,1,1");
week.put("Tuesday", "1,1,1,1,1,1,1,1");
week.put("Wednesday", "1,1,1,1,1,1,1,1");
week.put("Thursday", "1,1,1,1,1,1,1,1");
week.put("Friday", "1,1,1,1,1,1,1,1");
usermap.put("Week", week);
mDatabase.updateChildren(usermap);
Upvotes: 1