我无法在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;
}
以前使用的代码,我不确定发生了什么变化导致它停止工作。
答案 0 :(得分:3)
我不知道这是否是您想要做的,但如果您想将计数器增加1,请创建一个类型为数字的列并执行此操作:
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();
}
}
});