如何在Parse中添加列的值?

时间:2015-11-06 19:32:49

标签: java android parse-platform add

ParseObject money = new ParseObject("Money");
money.put("value", value);
money.put("description", description);

money.saveInBackground();

我正在开发Android应用程序,它是一种计算器。我添加数据来解析我赚了多少钱和花了多少钱,所以每行都有价值(多少钱)和描述。现在我需要添加列中的所有值" value"并在另一个活动中显示它。

我该怎么做?

2 个答案:

答案 0 :(得分:0)

Parse不支持通过查询进行聚合。您需要使用CloudCode来执行此操作,请查看此示例:https://parse.com/docs/cloud_code_guide#functions

答案 1 :(得分:0)

以下是如何计算总价值的示例:

private int getTotal() {
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Money");
    try {
        int total = 0;
        List<ParseObject> objects = query.find();
        for (ParseObject p : objects) {
            total += p.getInt("value");
        }
        return total;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return -1;
}