我想将firebaseRecyclerAdapter中的所有对象作为List。
这是我尝试的内容;
Query query = FirebaseDatabase.getInstance()
.getReference()
.child("ABC").orderByChild("abc");
FirebaseRecyclerOptions<myObject> options =
new FirebaseRecyclerOptions.Builder<myObject>()
.setQuery(query, myObject.class)
.build();
adapterL = new myAdapter(options, MyActivity.this);
ObservableSnapshotArray<myObject> mSnapshots=adapterL.getSnapshots();
if(mSnapshots.size()!=0) {
...
}
但总是我的mSnapshots大小为0.我想,可能还没有加载firebase适配器,但我不知道。
所以问题;在查询到firebase之后,如何获取firebase适配器中的对象列表?谢谢你的建议。
答案 0 :(得分:0)
你想要使用它:
snapshots.addChangeEventListener(object : ChangeEventListener {
override fun onChildChanged(
type: ChangeEventType,
snapshot: DocumentSnapshot,
newIndex: Int,
oldIndex: Int
) {
// An individual item has been changed
}
override fun onDataChanged() {
// A full update has been received and processed.
// Here's where you would use `snapshots` and process stuff
}
override fun onError(e: FirebaseFirestoreException) {}
})