【问题标题】:How to make a simple Twitter clone app with parse?如何使用解析制作一个简单的 Twitter 克隆应用程序?
【发布时间】:2019-12-03 14:00:23
【问题描述】:

我正在使用解析服务器在 android studio 中制作 Twitter 克隆,我想将推文和 cmets 存储在解析帐户中。我可以存储推文,但我不知道如何在我的解析帐户中存储该特定推文的 cmets。我想在我的应用程序的可扩展列表视图中安排所有推文及其 cmets。 我可以在解析服务器中使用 tweet 作为键和 cmets 作为值来存储 hashmap 吗?

【问题讨论】:

    标签: java android twitter parse-server


    【解决方案1】:

    您应该在您的应用程序中创建一个名为Comment 的新类,它应该有一个PointerTweet 类。然后您可以使用如下代码保存一个新的Comment 对象:

    // Create the comment
    ParseObject comment = new ParseObject("Comment");
    comment.put("content", "Some comment.");
    
    // Add a relation between the Tweet and Comment
    comment.put("tweet", ParseObject.createWithoutData("Tweet", "1zEcyElZ80")); // This is the tweet id to which the comment belongs
    
    // This will save both myPost and myComment
    comment.saveInBackground();
    
    

    参考:https://docs.parseplatform.org/android/guide/#relational-data

    【讨论】:

    • 所以当我评论其他人的推文时,我需要先使用 Parsequery 在我的 Tweet 类中找到该推文,然后将该推文与我的评论建立关系
    • 如果你已经有了Tweet id,你不需要使用解析查询来查找整个对象。您可以像上面的示例一样传递 id。但是,如果出于某种原因您已经不得不使用解析查询来查找推文对象,您也可以像这样直接传递它:comment.put("tweet", tweet);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多