So I'm Implementing an app using Parse.com as back end, There is basically 3 class in Parse. The first one User where I have the User's Information, and Gallery where I have images "like Instagram, and Finally Follow Class where I have the relation following and followers.
Now I have an activity where I have to display all the images for the people I'm following only. I couldn't write a correct relational queries to get the correct result.
so this is the code that display all the images in the database not only for the people I'm following.
public class FollowingImages extends ParseQueryAdapter<ParseObject> {
public FollowingImages (Context context) {
super(context, new ParseQueryAdapter.QueryFactory<ParseObject>() {
public ParseQuery create() {
ParseQuery<ParseObject> query = ParseQuery.getQuery("Gallery");
query.include("createdBy");
return query;
}
});
}
// Customize the layout by overriding getItemView
@Override
public View getItemView(final ParseObject object, View v, ViewGroup parent) {
if (v == null) {
v = View.inflate(getContext(), R.layout.list_item, null);
}
super.getItemView(object, v, parent);
// retrieving the Images from Parse.com
return v;
}
I don't know where should I apply the relational query in the constructor or inside getItemView.
please any help would be highly appreciated.
You will want to apply constraints to your query.
ParseQuery<ParseObject> query = ParseQuery.getQuery("Gallery");
query.whereEqualTo("createdBy", "theUserId");
query.findInBackground(new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (object == null) {
Log.d("score", "The find request failed.");
} else {
Log.d("score", "Retrieved the object.");
}
}
});
See the official guide for more details.