【发布时间】:2021-08-12 12:42:45
【问题描述】:
美好的一天。有什么方法可以实现这个吗?
val db = Firebase.firestore
val userID = Firebase.auth.currentUser!!.uid
val infoRef = db.collection("user").document(userID).collection("profile").document("info")
infoRef.get()
.addOnSuccessListener {document ->
if(document != null){
//get the data as cast to hashmap
val data = document.data as HashMap<*, *>
//get the username field and set text for greet user as the same value inside firestore
val username = data["username"] as String
tv_greet_user.text = "Hello, $username"
}
}
//将上面的代码提取为一个名为“getUsername()”的新方法
val 用户名:String = getUsername()
tv_greet_user.text = "Hello, $username"
【问题讨论】:
标签: android firebase kotlin google-cloud-firestore