Ad
Adding Value To A List In Firebase Database
I'm working on a Kotlin app. It requires me to create my custom data type (User.Item) that represents an item. I'm using a mutable list to work with it. However, I can't add to the list. I'm using Firebase Database
I've tried various Firebase tutorials but they don't seem to be giving me what I need.
val item = User.Item(firstName,expiry,userId,null,null)
mDatabaseReference!!.child(userId).child("items")
//User.Item
data class Item(
var name: String?="",
var expiry: String?=null,
var donator: String?=null,
var pickupGuy: String?=null,
var location: Location?=null
)
//User.user
data class user(var name: String? = "",
var password: String? = "",
var email: String? = "",
var phoneNumber: String?="",
var uid: String? = "",
var volunteer: Boolean?=false,
var items: List<Item>?= emptyList()
)
mDatabaseReference!!.child(userId).child("items") gives me a data reference. I would like it to be a list that I can manipulate. I've tried updateChildren(), setting it to a list and then pushing and then using that as a new value but nothing works.
The adding is done in AddItemActivity on line 94-95 Github link: https://github.com/dl1683/ShareEats
Ad
Answer
So I worked using the newdata push
val item = User.Item(firstName,expiry,userId,null,null)
val newData=mDatabaseReference!!.child(userId).child("items").push()
newData.setValue(item)
Ad
source: stackoverflow.com
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View
Ad