[英]Retrieving data from parse but they are not available outside the query
我想使用从getInBackground()
函数外部进行解析而获得的数据,但是字段的值为null
ParseQuery<ParseObject> query = ParseQuery.getQuery("Person");
query.getInBackground(invitedBy.getObjectId(), new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
// object will be your game score
//here the variables have an actual value
firstName = object.getString("firstName").toString();
lastName = object.getString("lastName").toString();
} else {
// something went wrong
}
}
});
//here the values for the firstName and lastName are null
invitorName.setText(firstName + " " + lastName);
任何建议如何解决此问题。 谢谢
正如@danh在注释中建议的那样,解析函数(findInBackground等)异步运行。 因此,在为firstName和lastName分配来自查询结果的任何值之前,textView可以设置这些变量的先前值。 如您所说,它们为null,可能是因为它们没有被赋予任何先验值。
您可以调用invitorName.setText(firstName + " " + lastName);
在回调中。
if (e == null) {
// object will be your game score
//here the variables have an actual value
firstName = object.getString("firstName").toString();
lastName = object.getString("lastName").toString();
invitorName.setText(firstName + " " + lastName);
}
或者您可以创建一个单独的函数,例如ex。
private void setText(final ParseObject object){
// put your logic here
}
在回调中
if (e == null) {
setText(object);
}
希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.