0

I have an object which contains 50 entries in it. What I want to do is, I want to pick 10 of them RANDOMLY.

Data contains only id (from 1 to 50) and some string.

To achieve this, I made a list of integers at the size of object (50). Then shuffled it, like so:

[3, 28, 27, 21, 5, 35, 46, 34, 40, 14, 49, 44, 2, 24, 22, 38, 20, 41, 6, 15, 12, 29, 30, 43, 26, 4, 1, 23, 10, 45, 42, 8, 18, 36, 13, 48, 16, 32, 39, 47, 7, 33, 37, 0, 19, 31, 25, 9, 17, 11]

Then I took first 10 items from this random list .

[3, 28, 27, 21, 5, 35, 46, 34, 40, 14]

But the question is, how can I request the items of these ids from Parse in one call?

I could make a loop of calls but that would be too much requests.

What I have: Ids of objects. What I want: Corresponding string values at these id numbers.

1 Answer 1

1

You will have to create a ParseQuery and then add the where clause:

Integer[] ids = {3, 5, 12, 23};
ParseQuery<ParseObject> query = ParseQuery.getQuery("YourObjectName");
query.whereContainedIn("yourObjectsIdField", Arrays.asList(ids));
query.findInBackground(new FindCallback<ParseObject>() {
    void done(List<ParseObject> results, ParseException e) {
        // enter code to execute after query has finished here
    }
});
Sign up to request clarification or add additional context in comments.

3 Comments

How to add a callback to this, where is the returned object?
I have edited my answer and added the code to actually execute the query in background and retrieve the list of results. There is a well documented manual on this on the Parse website: parse.com/docs/android/guide#queries
Not working for me while I am doing same...... query.whereContainedIn("objectId", Arrays.asList(ids)); I have to fetch all the row match with objectId

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.