Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
196 views
in Technique[技术] by (71.8m points)

Android Kotlin Firebase how to update values in a record

I'm using android studio 4.1.1 with Kotlin. I'm learning myself how to do android programming with Kotlin.

I'm trying to update records in my database.

my test firebase db

In my code I'm doing this:

val ref = FirebaseDatabase.getInstance().getReference("weights").child(userId).child(weight.recordID.toString())
println("!!!!!!!!!!! Firebase reference: ${ref.toString()}")


ref.child("comments").setValue(weight.comments.toString())
ref.child("date").setValue(weight.date.toString())
ref.child("exerciseText").setValue(weight.exerciseText.toString())
...

My println shows: ...I/System.out: !!!!!!!!!!! Firebase reference: https://my-test-app-860ca-default-rtdb.firebaseio.com/weights/oB3pzvhAr6foyhGZUuvFl4CECOw2/-MQTjdSW6TkJkDTzOKlv

That looks correct - matches the record I'm testing: userID and recordID in Firebase web console.

The setValue() code matches what I see in the Firebase docs: https://firebase.google.com/docs/database/android/read-and-write under setValue(). I've verified via println's that the values I'm passing in are present

I'm not seeing the records update in my list in my app or in the Firebase web console.

Any ideas what I'm missing? Is there some other command I have to run to actually commit the changes?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...