1

How can I query the specific value of an object in my Parse class and set it to a String? Given that I have an object with a specific objectId, I want the value for the "position" column, and I want to set it to a String.

    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("NativeAd");
    query.whereEqualTo("objectId", "fYBeufqdOt");
    query.findInBackground(new FindCallback() {

        @Override
        public void done(List objects, ParseException e) {
            if (e == null) {
                Log.d("NativeAd", "Retrieved " + objects.size());
                for (ParseObject adPosition : objects) {
                    String n = adPosition.get("position").toString();
                    System.out.println(n);
                }
            } else {
                Log.d("NativeAd", "Error: " + e.getMessage());
            }
        }

    });

1 Answer 1

2

i think this will work

@Override
public int getViewType(int position) {
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("NativeAd");
query.whereEqualTo("objectId", "fYBeufqdOt");
final String[] n =  new String[1]; 
query.getFirstInBackground(new GetCallback() {
    @Override
    public void done(ParseObject object, ParseException e) {
         n[0] = object.toString();
    }
});

int viewType = VIEW_TYPE_MARKET_FEED;
if ((position % n[0] == 0) && position > 0) {
    viewType = VIEW_TYPE_AD;
}
return viewType;

}

Now answers to your questions : n was declared in GetCallback anonymous class hence n has scope for that class only.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. This works. I didn't remember to set the String array, which makes sense in the context of retrieving a list.
Actually, do I not need to specifically call the position column to get the position value (nothing to do with variable int position by the way)?

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.