Bạn có chắc chắn muốn xóa bài viết này không ?
Bạn có chắc chắn muốn xóa bình luận này không ?
Kotlin Firebase Realtime Database – Get List of Data example | Android
https://grokonez.com/android/kotlin-firebase-realtime-database-get-list-data-example-android
Kotlin Firebase Realtime Database – Get List of Data example | Android
In previous post, we had known how to read/write single data object. Today, we're gonna look at way to get List of Data in an Android App.
Related Article:
Kotlin Firebase Realtime Database – Read/Write Data example | Android
More Practice:
Kotlin Firebase Realtime Database – Display List of Data with FirebaseRecyclerAdapter | Android
I. Way to get List of Data
0. Add Firebase to Android App
Please visit Kotlin - Add_Firebase_to_Android_App for details.
1. Write to specific child of a node
Before retrieving all data item from a list, we need a node that contains child nodes as data items. So we should write data to each node at first.
Assume that we have a class like this:
@IgnoreExtraProperties
class Message {
var author: String? = ""
var body: String? = ""
var time: String? = ""
constructor() {
// Default constructor required for calls to DataSnapshot.getValue(Message.class)
}
// ...
@Exclude
fun toMap(): Map {
val result = HashMap()
result.put("author", author!!)
result.put("body", body!!)
result.put("time", time!!)
return result
}
}
Use the updateChildren()
method, we can write data to specific child node without overwriting other child nodes (by specifying a path for the key):
More at:
https://grokonez.com/android/kotlin-firebase-realtime-database-get-list-data-example-android
Kotlin Firebase Realtime Database – Get List of Data example | Android





