我設法使用下面的代碼來獲取消防基礎數據的總和。然而,我願做更多的記錄,我只是pulled.To具體我想總和,因爲它們是數值..計算的數字火力記錄
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
//Getting the data from snapshot
DogExpenditure dogExpenditure = postSnapshot.getValue(DogExpenditure.class);
//Adding it to a string
String amount = "Amount: "+dogExpenditure.getAmount();
expenseList.add(expenses);
if (expenseList.size() == 1) {
adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, expenseList);
listview.setAdapter(adapter);
} else if (expenseList.size() > 1) {
}
System.out.println(expenses);
listview.setAdapter(adapter);
}
所以可能計算兩個數量的總和? 我DogExpenditure類是:
**public class DogExpenditure {
private String amount;
private String item;
public String getAmount() {
return amount;
}
public void setAmount(String amount) {
this.amount = amount;
}
public String getItem() {
return item;
}
public void setItem(String item) {
this.item = item;
}
}**
哪裏是你DogExpenditure類? – xFighter
我已經編輯我的問題@xFighter –