问题
I am new firebase developer, a am developing an android app, that using firebase database. 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.
Could you give me suggestion or have any idea ?
回答1:
Have you read this guide - Retrieve Data on Android ?
Example using 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);
来源:https://stackoverflow.com/questions/38219139/firebase-database-retrieve-data-from-database