clauub
clauub

Reputation: 1160

Add value to specific key and datetime

I have an app where are few users. Each user can save item to firebase. But when a user save an item that item save under a date time child, and under user name.

That's how my items are saved and users available

enter image description here

And instead of numbers (0,1,2) I want to appear date time and user name. Hope the question is ok i couldn't find any tutorial. Here is my code :

databaseReference = FirebaseDatabase.getInstance().getReference("jsonData").child("listaVanzatoareProduse");
            databaseReference.setValue(Util.getInstance().getVanzatorProduse());

            Util.getInstance().getVanzatorProduse().clear();

Upvotes: 0

Views: 49

Answers (1)

Century
Century

Reputation: 295

The .child() method creates a new node if it doesn't exists. so you can simply do:

databaseReference = FirebaseDatabase.getInstance().getReference("jsonData").child("listaVanzatoareProduse").child(dateTime).child(userName);
databaseReference.setValue(Util.getInstance().getVanzatorProduse());

Upvotes: 1

Related Questions