Firebase数据库获取子long值传递给我的类

时间:2017-04-12 07:13:29

标签: android firebase firebase-realtime-database

我不知道这里的错误是什么。我的所有长变量都得到0值。

这是我的倾听者

 public void onDataChange(DataSnapshot dataSnapshot) {

            serviceList.clear();
            for (DataSnapshot dsp : dataSnapshot.getChildren()) {
                serviceList.add(dsp.getValue(Service.class)); //add result into array list

            }

            serviceAdapter.notifyDataSetChanged();

        }

实际上代码运行良好,当我调试时,我可以看到dsp对象具有我想要的所有值。然后它传递给我的服务类对象,这里是结构:

    public class Service {

    private String durl;
    private Boolean active;
    private int poin;
    private long priceShort;
    private long priceMedium;
    private long priceLong;
    private long priceLongX;
    private String name;
    private String desc;
    private String category;


    public Service() {  //default constructor

    }

    public Service(String name, String desc,String durl, Boolean active, String category, int poin, long priceShort, long priceMedium, long priceLong, long priceLongX ) {
        this.name = name;
        this.desc = desc;
        this.durl = durl;
        this.active = active;
        this.category = category;
        this.priceShort = priceShort;
        this.priceMedium = priceMedium;
        this.priceLong = priceLong;
        this.priceLongX = priceLongX;
        this.poin = poin;

    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getDurl() {
        return durl;
    }

    public void setDurl(String durl) {
        this.durl = durl;
    }

    public Boolean getActive() {
        return active;
    }

    public void setActive(Boolean active) {
        this.active = active;
    }

    public int getPoin() {
        return poin;
    }

    public void setPoin(int poin) {
        this.poin = poin;
    }

    public long getPriceShort() {
        return priceShort;
    }

    public void setPriceShort(long priceShort) {
        this.priceShort = priceShort;
    }

    public long getPriceMedium() {
        return priceMedium;
    }

    public void setPriceMedium(long priceMedium) {
        this.priceMedium = priceMedium;
    }

    public long getPriceLong() {
        return priceLong;
    }

    public void setPriceLong(long priceLong) {
        this.priceLong = priceLong;
    }

    public long getPriceLongX() {
        return priceLongX;
    }

    public void setPriceLongX(long priceLongX) {
        this.priceLongX = priceLongX;
    }


}

添加到serviceList数组后,我检查了一些数组对象的值,除了所有我的长变量,如priceShort,priceMedium,priceLong和priceLongX,所有值都为0

我做了什么:

  1. 我重新检查了数据库的值,一切正常。

  2. 多次重启应用。

  3. EDIT / UPDATE: 这是我的服务json:

     "ServicesPrice" : {
        "sid1" : {
          "category" : "Hair-do",
          "desc" : "",
          "name" : "Gunting",
          "poin" : 15,
          "priceLong" : 0,
          "priceLongx" : 0,
          "priceMedium" : 0,
          "priceShort" : 100000
        },
        "sid10" : {
          "category" : "Hair-do",
          "desc" : "",
          "name" : "Coloring Matrix",
          "poin" : 25,
          "priceLong" : 525000,
          "priceLongx" : 625000,
          "priceMedium" : 450000,
          "priceShort" : 375000
        },
        "sid11" : {
          "category" : "Body Treatment",
          "desc" : "Pijat badan 60 menit",
          "name" : "Body Massage",
          "poin" : 15,
          "priceLong" : 0,
          "priceLongx" : 0,
          "priceMedium" : 0,
          "priceShort" : 125000
        },
        "sid12" : {
          "category" : "Body Treatment",
          "desc" : "Massage+Lulur+Sauna+Berendam Rempah+Shampoo Loreal",
          "name" : "Princess Spa",
          "poin" : 25,
          "priceLong" : 0,
          "priceLongx" : 0,
          "priceMedium" : 0,
          "priceShort" : 350000
        },
        "sid13" : {
          "category" : "Body Treatment",
          "desc" : "Lulur Susu + Body Bleaching",
          "name" : "Complete Whitening Milk Spa",
          "poin" : 30,
          "priceLong" : 0,
          "priceLongx" : 0,
          "priceMedium" : 0,
          "priceShort" : 500000
        },
    

    再一次,我可以获得除了所有价格之外的所有价值

1 个答案:

答案 0 :(得分:0)

我没有足够的声誉发表评论。只是为了确认,你在gradle中使用proguard和minifyEnabled吗?我测试了你的代码,我的价格恰到好处。