Firebase database - Retrieve data from database

六眼飞鱼酱① 提交于 2020-01-07 01:54:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!