简体   繁体   中英

How can I query a specific column value in a Parse.com class and set it to a string?

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());
            }
        }

    });

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM