[英]Firebase database - Retrieve data from database
I am new firebase developer, a am developing an android app, that using firebase database. 我是新的firebase开发人员,正在开发使用firebase数据库的android应用程序。 This is a part my database.
这是我数据库的一部分。
And this is my model class: 这是我的模型课:
public class Exam {
private String id;
private int subject;
private String school;
private Long examineDate;
private int likeCount;
private HashMap<String,Object> timeStampSubmit;
public Exam(){};
public Exam(String id, int subject, String school, Long examineDate, int likeCount) {
this.id = id;
this.subject = subject;
this.school = school;
this.examineDate = examineDate;
this.likeCount = likeCount;
HashMap<String, Object> timestampNowObject = new HashMap<String,Object>();
timestampNowObject.put(Constant.FIREBASE_PROPERTY_TIMESTAMP, ServerValue.TIMESTAMP);
this.timeStampSubmit = timestampNowObject;
}
}
I want to get and parse data from my database to a Exam object. 我想从数据库中获取数据并将其解析到Exam对象。
Could you give me suggestion or have any idea ? 你能给我建议还是有什么想法吗?
Have you read this guide - Retrieve Data on Android ? 您是否已阅读本指南-在Android上检索数据 ?
Example using ValueEventListener
使用
ValueEventListener
示例
ValueEventListener examListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Exam exam = dataSnapshot.getValue(Exam.class);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
ref.addValueEventListener(examListener);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.