这是我的 Firebase 实时数据库结构:
如何获取列表中的这些数据以将数据传递给模型类。
当我尝试像下面这样生成数据时,它起作用了。
listCourse = new ArrayList<>();
listCourse.add(new CourseModel("UserID", "CourseCode", "CourseName"));
listCourse.add(new CourseModel("122345", "TMN1234","System Programming"));
我只想以这种格式从 firebase 获取数据..
最佳答案
您可以通过此方法检索列表。
Firebase ref = new Firebase(FIREBASE_URL);
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
Log.i("Count " ,""+snapshot.getChildrenCount());
for (DataSnapshot postSnapshot: snapshot.getChildren()) {
CourseModel course = postSnapshot.getValue(CourseModel.class);
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Log.e("The read failed: " ,firebaseError.getMessage());
}
});
请参阅此文档:https://firebase.google.com/docs/database/android/lists-of-data
关于java - 数组中的 Firebase 数据检索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49715652/