I am new to the firebase database and is still learning a few things about it. I am trying to pull out data from the real-time database and I am having a hard time doing it.
my database layout is like this.
users
--UId
--firstname
--lastname
--dateofbirth
--mobile
--email
--type
my user model
data class User(val uid: String? = "",
val Firstname:String = "",
val Lastname:String = "",
val Mobile:String ="",
val Dateofbirth:String ="",
val email:String = "",
val type: String = ""
){
constructor(): this ("","","","","","","")
}
I am trying to pull out firstname, lastname, mobile, dateofbirth and email and attach it to my profile textfields for them fname,lname,dob,email
This is the code I am working with
private fun getUserInfo() {
val uid = FirebaseAuth.getInstance().currentUser!!.uid
val ref = FirebaseDatabase.getInstance().reference
val uidRef = ref.child("users").child(uid)
val valueEventListener: ValueEventListener = object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
for (I in dataSnapshot.children){
}
}
override fun onCancelled(databaseError: DatabaseError) {
Log.d("error", databaseError.message)
}
}
uidRef.addListenerForSingleValueEvent(valueEventListener)
}
How do I pull out that information?
Thanks for the help!