如何显示数据库的“评论”部分

时间:2020-10-04 06:10:07

标签: java firebase-realtime-database

我试图通过添加一个名为(“评论”)的子项来重组数据库,该子项应包括用户添加的评论,但是我一直在屏幕上显示为空。我只能假定变量尚未保存到模态类中。我以为我在模态类中调用getReview()应该可以工作:

     DatabaseReference reference = FirebaseDatabase.getInstance().getReference(); // getReference() is the root
        reference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                list.clear();
                for (DataSnapshot snapshot : dataSnapshot.getChildren()) {


                    Information info = snapshot.getValue(Information.class);
                    assert info != null;

                    String txt = "Medical Clinic: " + info.getName() + " \n\n " + "Review: " + info.getReview() + "\n\nServices Provided: " + info.getDorevitch() + " : " + info.getSkin_Cancer() + " : " + info.getEar_Suctioning();
                    list.add(txt);

  //      list.add(snapshot.getValue().toString());
                }

                adapter.notifyDataSetChanged();
            }

             This is my modal class

    enter code hepublic class Information {    // variables have to match in firebase database or it will show null
    private String Address;
    private String Name;
    private String Phone_No;
    private String Suburb;
    private String State;
    private String Postcode;
    private String Doctor;
    private String Dorevitch;
    private String Skin_Cancer;
    private String Ear_Suctioning;

    private String Reviews;

    public Information() {
    }

    public Information(String address, String name, String phone_No, String suburb, String state, String postcode, String dorevitch, String skin_cancer, String ear_suctioning, String doctor, String review) {
        Address = address;
        Name = name;
        Phone_No = phone_No;
        Suburb = suburb;
        State = state;
        Postcode = postcode;
        Doctor = doctor;
        Dorevitch = dorevitch;
        Skin_Cancer = skin_cancer;
        Ear_Suctioning = ear_suctioning;
        Reviews = review;
    }

    public String getDorevitch() {
        return Dorevitch;
    }

    public void setDorevitch(String dorevitch) {
        Dorevitch = dorevitch;
    }

    public String getSkin_Cancer() {
        return Skin_Cancer;
    }

    public void setSkin_Cancer(String skin_Cancer) {
        Skin_Cancer = skin_Cancer;
    }

    public String getEar_Suctioning() {
        return Ear_Suctioning;
    }

    public void setEar_Suctioning(String ear_Suctioning) {
        Ear_Suctioning = ear_Suctioning;
    }

    public String getState() {
        return State;
    }

    public void setState(String state) {
        State = state;
    }

    public String getDoctor() {
        return Doctor;
    }

    public void setDoctor(String doctor) {
        Doctor = doctor;
    }

    public String getSuburb() {
        return Suburb;
    }

    public void setSuburb(String suburb) {
        Suburb = suburb;
    }

    public String getReview() {
        return Reviews;
    }

    public void setReview(String review) {
        Reviews = review;
    }

    public String getAddress() {
        return Address;
    }

    public void setAddress(String address) {
        Address = address;
    }

    public String getName() {
        return Name;
    }

    public void setName(String name) {
        Name = name;
    }

    public String getPhone_No() {
        return Phone_No;
    }

    public void setPhone_No(String phone_No) {
        Phone_No = phone_No;
    }

    public String getPostcode() {
        return Postcode;
    }

    public void setPostcode(String postcode) {
        Postcode = postcode;
    }

enter image description here

enter image description here

我可以使它正常工作,但不知道为什么只有在通过执行以下代码而不使用模态类从数据库中拔出它时才起作用?

字符串评论= String.valueOf(snapshot.child(“ Reviews”)。getValue()); 字符串服务= String.valueOf(snapshot.child(“ Services”)。getValue());

String.valueof和toString()有什么区别?

0 个答案:

没有答案