I am using the Parse SDK for Android. I am not able to retrieve the data I stored in the cloud. I stored it manually using the Parse dashboard by creating a class called "Average" and creating a few rows. One of the columns is "squarefeet".
I want to retrieve the object whose "squarefeet" equals the value stored in the variable area.
What am I doing wrong? The compiler doesn't execute the done(params..) method. Below is the code.
ParseQuery<ParseObject> query = ParseQuery.getQuery("Average");
query.whereEqualTo("squarefeet", area);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objList, ParseException e) {
if (e == null) {
if (objList.size() > 0) {
for (int i = 0; i < objList.size(); i++) {
ParseObject p = objList.get(i);
averageConsumption = p
.getNumber("average_consumption");
efficientConsumption = p
.getNumber("efficient_consumption");
}
}
} else {
//something went wrong!
}
}
});
Use this
int area=120;
ParseQuery<ParseObject> query = ParseQuery.getQuery("Average");
query.whereEqualTo("squarefeet", area);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
Log.d("score", "Retrieved " + scoreList.size() + " scores");
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
Related
I am having a table structure like this trying to fetch multiple data all those related tables-
I have list of category (ProfileCateGory Object) and inside every category list (ProfileData Object) of profile Date with the there view count (ProfileViewCount Object)
I am new to this Parse.com I tried like this -
ParseQuery<ParseObject> query = ParseQuery.getQuery("ProfileData");
query.whereEqualTo("profileName", "Profile");
try {
for (int i = 0; i < query.count(); i++) {
query.getFirstInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (object == null) {
Log.d("ProfileData", "Error: " + e.getMessage());
} else {
Log.d("TAG", "Name: " + object.get("profileName").toString());
}
}
});
}
} catch (Throwable t) {
}
I am getting only one data from ProfileData.
You can use relational-queries
For that you have to make profileCode as Pointer type in ProfileViewCounts
ParseQuery<ParseObject> innerQuery = ParseQuery.getQuery("ProfileData");
innerQuery.whereEqualTo("profileName", "Profile");
ParseQuery<ParseObject> query =ParseQuery.getQuery("ProfileViewCounts");
query.whereMatchesQuery("profileCode", innerQuery);
query.getFirstInBackground(new GetCallback<ParseObject>() {
#Override
public void done(ParseObject objProfileViewCounts, ParseException e) {
// TODO Auto-generated method stub
}
});
getFirstInBackground() is to call and return just one item.
To get an array or more objets you need to do:
//profile or id of user , you have to pass as a parameter
ParseQuery<ParseObject> query = ParseQuery.getQuery("ProfileData");
query.whereEqualTo("profileName", Profile);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
for (int inP = 0; inP < objects.size(); inP++) {
String profileName = objects.get(inP).getString("profileName");
}
} else {
}
}
I'm using Parse in a android, the problem I'm facing right now is that when I do a query it doesn't do it, it skip the lines, for example:
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.countInBackground(new CountCallback() {
public void done(int count, ParseException e) { //skip all of thisthis
if (e == null) {
num=count;
} else {
//error
}
}
});
So, I'm not able to get the results, what I'm doing wrong?
Use
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> objects, ParseException e) {
if (e == null) {
// The query was successful.
num = objects.size();
} else {
// Something went wrong.
}
}
});
There are many different types of query depends on what you want to. So if you're doing a query to get total number of users or objects in list. It can be done in the following manner.
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
query.countInBackground(new CountCallback() {
public void done(int count, ParseException e) {
if (e == null) {
// The count request succeeded. Log the count
num = count;
Log.d("Count", "Total number of users is " + num);
} else {
// The request failed
}
}
});
I am trying to count number of user in my parse db and pass it to my sliding menu as a counter. However, it is always returned as null (I have more than 100users in parse user db). My code in the sliding menu as follows:
Any idea?
countuser = 0;
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> users, ParseException e) {
if (e == null) {
// Success
mUsers = users;
countuser = mUsers.size();
}
}
});
I want to pass the counuser to my navigation item :
navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons
.getResourceId(3, -1), true, "("+ countuser +")"));
This is covered in the documentation under Android, Queries, Counting Objects.
ParseQuery<ParseUser> query = ParseUser.getQuery();
// set any filters...
query.countInBackground(new CountCallback() {
public void done(int count, ParseException e) {
if (e == null) {
// all good
countuser = count;
}
}
});
in case that someone came here:
in new parse-server you can try this:
ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
query.whereEqualTo("playerName", "Dan Stemkoski");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
Log.d("score", "Retrieved " + scoreList.size() + " scores");
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
the scoreList.size() return the count
I am facing a big problem in parse api. I am able to create new group on server as well able to add user to the group also. I created many group on server like Friends, Sports, College etc. But how can I retrieve the names of all group from server?
Using the below code I can retrieve all the user in the group.
public void getUserList() {
String groupName="Friends"
final ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
ParseRelation relation = currentUser.getRelation(groupName);
ParseQuery query = relation.getQuery();
try {
Log.e("Size ", "Size " + query.count());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// query.whereEqualTo("username", null);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException arg1) {
// TODO Auto-generated method stub
try {
for (int i = 0; i < objects.size(); i++) {
ParseObject r = objects.get(i);
String name = r.getString("username").toString();
Log.e("user name ", "===>" + name);
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"Error : " + e.toString(), 1).show();
}
}
});
}
}
In above screen-shot I need all the names like Friends, MYGroup and xyz using one query.
Please help me.
To get all groups, you need to query the Group class (or whatever you have called it):
ParseQuery<ParseObject> query = ParseQuery.getQuery("Group");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> groupList, ParseException e) {
if (e == null) {
for (ParseObject group : groupList) {
Log.d("group", "Group name: " + group.get("name");
}
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
i have this code: where i retrieve the courses of a certain student that is loged with the name in "NameCurrentStudent" and then stock the courses in an ArrayList
ParseQuery<ParseObject> query = ParseQuery.getQuery("Courses");
query = query.whereEqualTo("Student", NameCurrentStudent);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> courseList, ParseException e)
{
if (e == null)
{
courses.clear();
for (ParseObject course : courseList)
{
courses.add(course.getString("NameCourse"));
}
}
else
{
Log.d("Post retrieval", "Error: " + e.getMessage());
}
}
});
but when i use debug it skipps query.findInBackground(new FindCallback() {
anyone know's why ?
ParseQuery<ParseObject> queryP = ParseQuery.getQuery("Courses");
queryP.whereEqualTo("Student", nameStudent);
queryP.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> coursesList, ParseException e)
{
ArrayList<String> courses = null;
if (e == null)
{
courses = new ArrayList<String>();
for (ParseObject course : coursesList)
{
String courseName = course.getString("CoursesNameInParseColumn");
courses.add(courseName);
}
}
else
{
Log.d("Post retrieval", "Error: " + e.getMessage());
}
populateCoursesList(courses);
}
});