我必须尝试将数据下载到ArrayList中。当我在done()方法中调用它时,可以,但是当我在done()方法中调用它时,它将为null。我该如何解决?
ParseQuery<ParseObject> query = ParseQuery.getQuery("code");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> provineList, ParseException e) {
if (e == null) {
for (ParseObject mProvine : provineList) {
Provine provine = new Provine();
provine.setPro((String) mProvine.get("provine"));
provine.setNumber((String) mProvine.get("code_number"));
provines.add(provine);
Log.d("All provine", provines.get(i).getPro()); (it's ok, no problem).
i++;
}
} else
Log.d("Provines", "Error: " + e.getMessage());
}
}
});
Log.d("All provine", provines.get(0).getPro()); (it's null ).
最佳答案
您可以声明扩展ParseObject
的子类。
在调用ParseObject.registerSubclass(YourClass.class)
之前,在Application构造函数中调用Parse.initialize()
。
遵循此Subclasses
https://www.parse.com/docs/android/guide#objects-subclassing-parseobject
// Armor.java
import com.parse.ParseObject;
import com.parse.ParseClassName;
@ParseClassName("Armor")
public class Armor extends ParseObject {
}
// App.java
import com.parse.Parse;
import android.app.Application;
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
ParseObject.registerSubclass(Armor.class);
Parse.initialize(this, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY);
}
}
在查询时,您将该数据作为ArrayList获得。
ParseQuery<Armor> query = ParseQuery.getQuery(Armor.class);
query.whereLessThanOrEqualTo("rupees", ParseUser.getCurrentUser().get("rupees"));
query.findInBackground(new FindCallback<Armor>() {
@Override
public void done(List<Armor> results, ParseException e) {
// here you can use results same as object model.
}
});