【问题标题】:How do you increment on parse.com你如何在 parse.com 上增加
【发布时间】:2016-01-19 16:13:51
【问题描述】:

我在 parse.com 上增加值时遇到问题。什么都没有发生,值保持在 0。

首先我在 postactivity 中将值设置为 0:

Counter count = new Counter();
int Counts = 0;
count.setVote(counts);
count.saveInBackground();

在我的 parse.com 课程中,我有:

public int getVote() {
    return getInt("vote");
}

public void setVote(int value) {
    put("vote",value");
}

MainActivity我有:

public View getItemView(final Counter count,View view,ViewGroup parent) {
    if(view==null) {
        view = View.inflate(getContent(),R.layout.count_item,null);
    }

    ImageButton vote=(ImageButton) view.findViewById(R.id.btnvoteup);
    vote.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                count.increment("vote",1);
                count.saveInBackground();
            }
        });
    return view;
}

以前的代码可以工作,但我不确定是什么改变导致它停止工作。

【问题讨论】:

  • 你能正确地格式化你的问题吗?
  • 你如何测试它是否有效?

标签: android parse-platform increment


【解决方案1】:

我不知道这是否是您想要做的,但如果您想将计数器加 1,请创建一个类型为 number 的列并执行以下操作:

ParseQuery<ParseObject> query = ParseQuery.getQuery("ClassName");

// Retrieve the object by id
query.getInBackground("xWMyZ4YEGZ", new GetCallback<ParseObject>() {
  public void done(ParseObject myobject, ParseException e) {
    if (e == null) {
      // Now let's update it with some new data. In this case, only cheatMode and score
      // will get sent to the Parse Cloud. playerName hasn't changed.
     myobject.increment("score");
     myobject.saveInBackground();
    }
  }
});

【讨论】:

  • 不客气!如果觉得有用请采纳我的回答
猜你喜欢
  • 1970-01-01
  • 2021-09-27
  • 2020-03-24
  • 2019-06-25
  • 1970-01-01
  • 2016-01-16
  • 2021-03-28
  • 1970-01-01
  • 2021-07-19
相关资源
最近更新 更多