简体   繁体   中英

Firebase database - Retrieve data from database

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 ?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM