Reputation: 27
Hey guys I was looking through parse.com examples and documentation but haven't been able to figure out how to change the value of something that's stored in a column in a parse class(specifically a string that's a number e.g., Column name:ExampleColumn - string - 5) . For example I want to do something like this when a button is clicked
@Override
public void onClick(View arg0) {
ParseQuery<ParseObject> query = new ParseQuery<ParseObject> ("ExampleClass");
ExampleColumn = ExampleColumn + 1; /* obviously this won't work but it shows exactly what i want to do with the column, so that this would make ExampleColumn = 6 */
}
Upvotes: 0
Views: 219
Reputation: 466
If the column data type is string you have to convert to integer before increment it.
ParseQuery query = new ParseQuery ("ExampleClass");
query.whereEqualTo("objectId",your_object_id);
query.getFirstInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (object == null) {
Log.d("score", "The getFirst request failed.");
} else {
int val=Integer.parseInt(object.getString("exampleColumn"));
val++;
object.put("exampleColumn",val);
object.saveInBackground();
}
}
});
Upvotes: 0
Reputation: 9942
With Parse, you don't work directly with columns. You work with objects. So, if you want to change the value of "a column", you need to
Upvotes: 1