Android Firebase模型类

时间:2017-09-19 18:17:08

标签: android firebase firebase-realtime-database

这是我的模型类

public class Sell {


private String transactionID;
private int dollarPrice;
private boolean isInParts;
private String itemName;


public Sell() {
}


public Sell(String transactionID,
            int dollarPrice,
            boolean isInParts,
            String itemName) {

    this.transactionID = transactionID;
    this.dollarPrice = dollarPrice;
    this.isInParts = isInParts;
    this.itemName = itemName;
}


public String getTransactionID() {
    return transactionID;
}

public int getDollarPrice() {
    return dollarPrice;
}

public boolean isInParts() {
    return isInParts;
}

public String getItemName() {
    return itemName;
}



public void setTransactionID(String transactionID) {
    this.transactionID = transactionID;
}

public String getSellingString() {
    String string = "I want to Sell "+DOLLAR_SIGN+dollarPrice+ " "+itemName;

        if (isInParts) {
            string +=  " in Parts";
            // I want to sell $100 Goods in Parts
        }
    }
    return string;
  }
}

当我将它提交给firebase时 使用以下参数

  

transactionId =“6475xxx-xxxxxxxxxxx”   dollarPrice = 100   inParts = true   itemName =“商品”

我在我的firebase仪表板中获得以下内容

{
 "dollarPrice" : 100,
 "inParts" : true,
 "itemName" : "Goods",
 "transactionID" : "6475xxx-xxxxxxxxxxx"
}

但在我的回收站视图的视图持有者中,我有一个文本视图,我设置了以下文本

textview.setText(sell.getSellingString());

我的textView始终显示

  

我想出售100美元商品

而不是

  

我想卖出100件商品零件

从而忽略了我指定的布尔值。

我怎样才能解决这个问题?

1 个答案:

答案 0 :(得分:1)

此 => Firebase won't bind boolean value to field

回答了我的问题。

尝试获取布尔值时

 private boolean up;
 public boolean isUp() {
    return up;
 }
  

如果您的布尔字段名为 isUp ,则必须将getter命名为 isIsUp() getIsUp()。或者,如果您想要一个名为 isUp 的getter,则字段名称将为 up