I need to add data to an array stored in the database to be like this: places:
0:"new Item"
1:"new Item",
2:"new Item"
.
.
.
My problem is How to push data in array stored in the Firebase without the need to use a Hashmap? For exemple the next data pushed will result on:
places: 0:"old Item"
1:"vItem",
2:"old Item",
3:"new Item"
I know that if i use the method given bellow, the data will be erased and a new data set will be added,
Utils.eventsRef.child(events.getUid()).child("arrayTicket").setValue(str);
Can someone help me please ?
According to your comments, to be able to add an array into your Firebase realtime database, you need first to convert your array to a List like in the following lines of code:
String[] items = {"newItem", "newItem", "newItem"};
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference arrayTicketRef = rootRef.child("arrayTicket");
arrayTicketRef.setValue(Arrays.asList(items));
The result in your Firebase console will be:
Firebase-root
|
--- arrayTicket
|
--- 0: "newItem"
|
--- 1: "newItem"
|
--- 2: "newItem"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With