对于我的Android应用程序,我已经将ParseObject子类化为 Food , Pref 类和 CustomUser类,它扩展了ParseUser 并创建了一个关系“恋人“介于'食物'和'用户'之间。
在CustomUser对象中,我使用了存储Pref对象 键“pref”中的createWithoutData方法.CustomUser及其 各个Pref对象具有一对一映射
因此,当我想使用ParseQueryAdapter在列表视图中显示特定食物的所有爱好者时,
ParseQueryAdapter<ParseObject> adapter = new ParseQueryAdapter<ParseObject>(getActivity(),
new ParseQueryAdapter.QueryFactory<ParseObject>() {
public ParseQuery<ParseObject> create() {
ParseQuery<ParseObject> query = food.getRelation("lovers").getQuery();
query.selectKeys(Arrays.asList("pref");
return query;
}
});
adapter.setTextKey(Pref.COLUMN_PROFILE_NAME); adapter.setImageKey(Pref.COLUMN_PROFILE_PIC_THUMB);
fyi,COLUMN_PROFILE_NAME =“profileName”,COLUMN_PROFILE_PIC_THUMB =“profileThumb”
现在的问题是“pref”只是对实际对象的引用。因此,当listView尝试获取文本和图像时,它会显示“ParseObject没有此密钥的数据。调用fetchIfNeeded()以获取数据”
我的目标是将查询传递给ParseQueryAdapter,该查询将获取嵌套在CustomUsers中的所有pref对象,这些对象与该特定食物有“恋人”关系。
解析文档说'include'方法对关系不起作用。
请帮助,我一直在努力解决这个问题。
答案 0 :(得分:1)
要检索关系,我认为您不能使用查询。在您的情况下,您将使用
ParseRelation<ParseObject> relation = user.getRelation("lovers");
希望这有帮助
答案 1 :(得分:0)
下面是一个展示此类可用配置级别的示例:
// Instantiate a QueryFactory to define the ParseQuery to be used for fetching items in this
// Adapter.
ParseQueryAdapter.QueryFactory<ParseObject> factory =
new ParseQueryAdapter.QueryFactory<ParseObject>() {
public ParseQuery create() {
ParseQuery query = new ParseQuery("Customer");
//query.whereEqualTo("activated", true);
//query.orderByDescending("moneySpent");
query.include("your key");
return query;
}
};
// Pass the factory into the ParseQueryAdapter's constructor.
ParseQueryAdapter<ParseObject> adapter = new ParseQueryAdapter<ParseObject>(this, factory);
adapter.setTextKey("name");
// Perhaps set a callback to be fired upon successful loading of a new set of ParseObjects.
adapter.addOnQueryLoadListener(new OnQueryLoadListener<ParseObject>() {
public void onLoading() {
// Trigger any "loading" UI
}
public void onLoaded(List<ParseObject> objects, ParseException e) {
// Execute any post-loading logic, hide "loading" UI
}
});
// Attach it to your ListView, as in the example above
ListView listView = (ListView) findViewById(R.id.listview);
listView.setAdapter(adapter);