I want to retrieve value from the class of the object.
example: I have one class Player_info.
In this class there is different field like Player name,Score,birthdate.
1.messi,50,7/12/1991.
2.ronaldo,45,7/7/1993.
3.rooney,40,7/12/1991.
now i want to retrieve data ronaldo score which is from this class using parse i was stuck over here from 2 day. plz guys help me out. It was very appreciable.
You need to do like this :
String ObjectId;
ParseQuery<ParseObject> playerQuery = ParseQuery.getQuery("Player_info");
playerQuery.whereEqualTo("Player Name", "ronaldo");
playerQuery.setLimit(1);
playerQuery.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> playerList, ParseException e) {
if (playerList != null && playerList.size() > 0) {
int score = playerList.get(0).getInt("Score");
objectId = playerList.get(0).getObjectid();
}
}
}
Now you can use score of ronaldo wherever you want :) .
To update the value in table you can do that:
// Create a pointer to an object of class Point with id dlkj83d
ParseObject point = ParseObject.createWithoutData("Player_Info", objectId);
// Set a new value on quantity
point.put("Score", newScore);
// Save
point.saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e == null) {
// Saved successfully.
} else {
// The save failed.
}
}
});
Related
I feel like I'm pretty close on this one, just need the last bit.
I have the following tables:
_User (standard Parse table)
Category (object Id, name)
Exercises (object Id, name, description, thumbnail, image, etc)
and UserFavourites which is where I store the user's preferred exercises
(objectId, user->users table, exercise->exercises table, category->category table)
I have writing to Parse using pointers just fine:
//create new parse object
ParseObject favouriteExercise = new ParseObject("UserFavourites");
//create pointers to the Exercise table and Category table
ParseObject exercise = ParseObject.createWithoutData("Exercises", mExerciseId);
ParseObject category = ParseObject.createWithoutData("Category", mCategoryId);
//put those pointers into the Userfavourites table and save
favouriteExercise.put("user",ParseUser.getCurrentUser());
favouriteExercise.put("exercise",exercise);
favouriteExercise.put("category",category);
//save
favouriteExercise.saveInBackground();
Now I'm trying to retrieve all the exercises a user has favourited and put them in to a listview by searching the table for any objects that match the user's pointer to the user's table:
ParseQuery<Exercises> query = ParseQuery.getQuery("UserFavourites");
final ParseObject user = ParseObject.createWithoutData(ParseUser.class, ParseUser.getCurrentUser().getObjectId());
query.whereEqualTo("user", user);
//call to parse.com to start the query
query.findInBackground(new FindCallback<Exercises>() {
#Override
public void done(List<Exercises> exercises, ParseException e) {
if (exercises != null) {
Toast.makeText(getApplicationContext(), "Favourites found, can't list yet", Toast.LENGTH_SHORT).show();
mAdapter.clear();
//add all the exercises to the list
mAdapter.addAll(exercises);
//sort the list alphabetically
mAdapter.sort(new Comparator<Exercises>() {
#Override
public int compare(Exercises exercises, Exercises t1) {
return exercises.getName().compareTo(t1.getName());
}
});
} else {
mNoFavourites.setVisibility(View.VISIBLE);
}
Where I'm stuck is when I run this I can see my query is working -> I am retrieving the 4 rows in UserFavourites that I favourited out of the table of 8, so it is filtering correctly, but the objects I'm getting aren't pointing to the exercises I want. They are just empty pointers.
Thanks.
Yes it will return only reference (Pointer). If you want actual object data call fetchInBackground
myObject.fetchInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
// Success!
} else {
// Failure!
}
}
});
I figured it out based on the logic kishore jethava gave.
I queried the favorites table, then with the results I wanted (which pointed to another table) I cycled through each result and got the object it pointed to and added it to my ArrayList.
public void getFavourites() {
//set progress bar
setProgressBarIndeterminateVisibility(true);
ParseQuery<Exercises> query = ParseQuery.getQuery("UserFavourites");
final ParseObject user = ParseObject.createWithoutData(ParseUser.class, ParseUser.getCurrentUser().getObjectId());
query.whereEqualTo("user", user);
query.include("exercise");
//call to parse.com to start the query
query.findInBackground(new FindCallback<Exercises>() {
#Override
public void done(List<Exercises> objects, ParseException e) {
if (objects.size() != 0) {
for(ParseObject object : objects)
{
//for each pointer found, retrieve the object it points to
obj = object.getParseObject("exercise");
mAdapter.add((Exercises) obj);
}
});
}
} else {
mNoFavourites.setVisibility(View.VISIBLE);
}
//stop progress bar
setProgressBarIndeterminateVisibility(false);
}
});
}
Hi im trying to add data to specific object in some table in parse.com this is the code :
ParseQuery<ParseObject> query = ParseQuery.getQuery("Buildings");
query.whereEqualTo("objectId", building);
query.getFirstInBackground(new GetCallback<ParseObject>() {
#Override
public void done(ParseObject object, ParseException e) {
if(object == null) {
Log.e("object","not found");
}
else {
Log.e("object","found "+ object.getObjectId().toString());
object.put("test", "test");
object.saveInBackground();
}
}
});
i debug the code and it was fine and he really find the object and it really add a column to the table with the name test but i dont see any value inside i just see all the time (undefined)
Currently I am making an Android application with Android Studios and I am using Parse to handle the data. I want to be able send (put) data such as town names and info about that town (town_names would be a column and info would be another, there for each town_names would have its own info). I can do that with ease and it uploads to the Parse database. However, the part I can not seem to figure out is how to retrieve the data points I desire. I have code to retrieve data based off of an objectId shown below however that is not exactly what I want.
ParseQuery<ParseObject> query = ParseQuery.getQuery("userMessage");
query.getInBackground("KgsLojXPcq", new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
retrievedText = object.getString("info");
} else {
retrievedText = "No information.";
}
}
});
"userMessage" is the ParseObject I have created and "info" is the column I want to get text from. Instead of searching for an objectId ("KgsLojXPcq") is there a way to search for town_names? So then I could for example search the database for "New York" and "retrievedText" would be set to the info for New York.
ParseQuery
.getQuery("userMessage")
.whereEqualTo("town_names", "New York")
.getFirstInBackground(new GetCallback<ParseObject>() {
#Override
public void done(ParseObject object, ParseException e) {
if (e == null) {
retrievedText = object.getString("info");
} else {
retrievedText = "No information.";
}
}
});
I am working with parse.com.
I saved a geopoint in my table GPSLocation.
Now I want to update the existing row again and again but the problem is that my given code always create a new row.Please help me for that.
the code to save data is
ParseGeoPoint loc=new ParseGeoPoint(latitude,longitude);
ParseObject GPS = new ParseObject("GPSLocation");
GPS.put("location", loc);
GPS.saveInBackground();
code to get data and update is here
ParseQuery<ParseObject> query=new ParseQuery<ParseObject>("GPSLocation");
query.getInBackground("5dL98RycoD", new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
ParseGeoPoint loca;
loca=object.getParseGeoPoint("location");
object.put("location", loca);
object.saveInBackground();
// object will be your game score
} else {
// something went wrong
}
}
});
Any help is appreciated.
I am using Parse backend for my android app. I need to query the database for a record that has a field with a specific string value. following is the Parse code
strObjectId is a String initialised with a Parse ObjectId as follows
String strObjectId = MyParseObject.getObjectId();
Parse code
ParseQuery<ParseObject> query = ParseQuery.getQuery("MyDataTable");
query.whereEqualTo("code", Code);
query.getFirstInBackground(new GetCallback<ParseObject>()
{
public void done(ParseObject object, ParseException e)
{
if (object == null)
{
return;
}
else
{
ShowToast("Record found!");
}
}
});
The problem is that it works perfectly okay when 'Code' is hardcoded as follows prior to running above query
String Code = "krErZgz9Is";
But it DOES NOT work when Code is assigned Parse ObjectId as follows
String Code = strObjectId;
Obviously the Data Table does have a record with 'code' field with value 'krErZgz9Is'
Your help will be appreciated
Thanks
Have you tried to print out the strObjectId? If your object is not yet saved in Parse, or the object is not loaded from Parse. It will not have an object Id.
Also, have you tried to check the equality with the objectId directly?
query.whereEqualTo("code", MyParseObject.getObjectId());
I've got this working for me
I created an EditText and contained the text I want to find a match in my query. Just try to hide it in the layout if you don't really want to show it.
EditText editText = (EditText) findViewById(R.id.editText);
editText.setText(strObjectId);
ParseQuery<ParseObject> query = ParseQuery.getQuery("MyDataTable");
query.whereEqualTo("code", editText.getText().toString());
query.getFirstInBackground(new GetCallback<ParseObject>()
{
public void done(ParseObject object, ParseException e)
{
if (object == null)
{
return;
}
else
{
ShowToast("Record found!");
}
}
});
I don't get it why removing the getText() function doesn't work so you better keep it this way.