[英]ParseQueryAdapter in parse listview and many-to-many relations [Parse.com]
I am developing an android application and I really liked parse and planning to use it again in future projects. 我正在开发一个Android应用程序,我真的很喜欢解析并计划在未来的项目中再次使用它。 So this app is my senior project...
所以这个应用程序是我的高级项目......
1st. 1。 I tried a many-to-many "_User"relation but couldn't figure out the queries or couldn't add another user to the existing user relation successfully.
我尝试了多对多的“_User”关系,但无法弄清楚查询或无法成功将其他用户添加到现有用户关系。
2nd. 第2位。 I created a "contact" ParseObject class pointing for each user pointing at it's creator, and I could successfully add other contacts into a contact, it's contact-to-contact relation and I called it "has"
我创建了一个“联系人”ParseObject类,指向指向它的创建者的每个用户,我可以成功地将其他联系人添加到联系人中,它是联系人与联系人的关系,我称之为“有”
3rd. 3。 And now I can see the relation in my data browser,and everything including (create, update, delete, get)is going great... BUT MY PROBLEM IS #4 !
现在我可以在我的数据浏览器中看到关系,包括(创建,更新,删除,获取)在内的所有内容都很棒......但我的问题是#4!
4rth. 4rth。 I have a class that extends ListFragment and I want to query the contacts in my "contact" relation for the ParseQueryAdapter... I tried all the methods and I either get a null pointer exception or my app crashes...
我有一个扩展ListFragment的类,我想查询ParseQueryAdapter的“联系人”关系中的联系人...我尝试了所有的方法,我得到一个空指针异常或我的应用程序崩溃...
I can get all the contacts to show though using this line of code: 我可以使用以下代码行显示所有联系人:
ParseQueryAdapter adapter = new ParseQueryAdapter(getActivity(), MyContactClass.class);
ParseQueryAdapter adapter = new ParseQueryAdapter(getActivity(),MyContactClass.class);
But tried all the queries in relational tutorials and it didn't work out... I understand Parse logic but can't figure out the code implementation... 但尝试了关系教程中的所有查询并且它没有成功...我理解Parse逻辑但无法弄清楚代码实现...
A [contact] has ---> a [List}...... I want to get that list, any Java sample code to do that? 一个[联系方式]有--->一个[List} ......我想获得那个列表,任何Java示例代码都可以做到这一点?
PLEASE AND THANK YOU :) I never ask a question unless I'm desperate... 请和谢谢你:)我绝不会问一个问题,除非我绝望...
I was able to solve this by NOT using the getInBackground(with Callback) method... I modified the code to the following: 我能够通过不使用getInBackground(带回调)方法解决这个问题...我将代码修改为以下内容:
ParseQueryAdapter<ParseObject> adapter = new ParseQueryAdapter<ParseObject>(getActivity(), new ParseQueryAdapter.QueryFactory<ParseObject>() {public ParseQuery<ParseObject> create() {
// Here we can configure a ParseQuery to our heart's desire.
final ParseQuery<ParseObject> cUser = ParseQuery.getQuery("contact");
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("contact");
try
{
query=cUser.get("MyObjectIdGoesHere").getRelation("has").getQuery();
} catch (ParseException e)
{
e.printStackTrace();
}
return query;
}
});
adapter.setTextKey("screenName");
setListAdapter(adapter);
It was really frustrating and I hope that someone could benefit from the solution that fitted my code... 这真的令人沮丧,我希望有人可以从适合我的代码的解决方案中受益...
Sorry to hear that. 很抱歉听到这个消息。 By chance I had Parse Android Anywall Project opened with my project.
我偶然用我的项目打开了Parse Android Anywall Project。 In this example project, the following code can help achieve your goal.
在此示例项目中, 以下代码可帮助您实现目标。
I tried to post codes here, can't past the formatting requirement of stackoverflow. 我试图在这里发布代码,不能超过stackoverflow的格式化要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.