第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

如何計(jì)算列表中相似的id對象并顯示在recyclerview中?

如何計(jì)算列表中相似的id對象并顯示在recyclerview中?

嗶嗶one 2023-01-05 10:03:19
我有一個(gè) JSON 數(shù)組,因?yàn)槲倚枰褂?ParentCommentID 進(jìn)行匹配計(jì)數(shù),并使用文本視圖將數(shù)據(jù)解析到 recyclerview 中,同時(shí)計(jì)數(shù)我只得到一個(gè)位置的數(shù)字計(jì)數(shù),其他項(xiàng)目也一樣,任何幫助。{  "d": {    "results": [      {        "__metadata": {          "id": "e7433825-6771-4f5e-96c7-c4d2674d7764",          "uri": "",          "etag": "\"2\"",          "type": "SP.Data.InquiryDiscussionsListListItem"        },        "Author": {          "__metadata": {            "id": "f064775c-6161-4bdb-9f4d-8bc6a898d218",            "type": "SP.Data.UserInfoItem"          },          "Title": "Submitter1"        },        "Id": 1501,        "ID": 1501,        "Title": null,        "Created": "2019-06-06T04:15:17Z",        "ParentCommentID": "1439",        "Comment": "<div class=\"ExternalClass8C333A77B6564A53BED74CA1BA2D2A10\">        reply add for 009</div>",        "CommentType": null,        "CommentDocumentName": null,        "AppID": "1083",        "Role": "Customer"      },      {        "__metadata": {          "id": "e92f708f-93dc-4587-8c4f-5518ed24f360",          "uri": "",          "etag": "\"2\"",          "type": "SP.Data.InquiryDiscussionsListListItem"        },        "Author": {          "__metadata": {            "id": "209d2d9a-bb07-4064-aaa0-231ad881a80f",            "type": "SP.Data.UserInfoItem"          },          "Title": "Submitter1"        },        "Id": 1500,        "ID": 1500,        "Title": null,        "Created": "2019-06-06T04:14:55Z",        "ParentCommentID": "1439",        "Comment": "<div class=\"ExternalClass44B1A0BB4D314C57BEE20141BFF10491\">comment add for       009</div>",        "CommentType": null,        "CommentDocumentName": null,        "AppID": "1083",        "Role": "Customer"      },      {        "__metadata": {          "id": "ec112002-3132-4bc1-8f85-03fbd9fda11d",          "uri": "",          "etag": "\"2\"",          "type": "SP.Data.InquiryDiscussionsListListItem"        },      }    ]  }}例如 id 1439,有兩個(gè)ParentCommentID,所以在這種情況下,對于 id1439應(yīng)該有兩條評論,我試圖在我的 recyclerview 適配器中使用 for 但它不起作用。
查看完整描述

1 回答

?
吃雞游戲

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊

我認(rèn)為您需要遍歷結(jié)果列表,當(dāng)您找到具有父評論的結(jié)果時(shí),您進(jìn)入地圖,獲取父評論,將其計(jì)數(shù)加一并將其粘貼回地圖中:


假設(shè)您的 Result 類是這樣的:


class Result {

    private String id;

    private String parentCommentID;


    public Result(String id, String parentCommentID) {

        this.id = id;

        this.parentCommentID = parentCommentID;

    }


    // GETTERS/SETTERS

}

你有一個(gè)包含 3 個(gè)結(jié)果的討論列表


    discussionsList = Arrays.asList(

        new Result("1439", null),

        new Result("1500", "1439"),

        new Result("1801", "1439")

    );

像你的情況一樣, 1439 沒有父母, 1500 和 1501 都有 1439 作為父母


然后你可以做這樣的事情:


Map<String, Integer> commentsCountMap = new HashMap<>();

// Loop through the discussion Map

for(Result res : discussionsList) {

    String parentCommentId = res.getParentCommentID();

    // If the Result has a parent comment

    if(parentCommentId != null) {

        // get the count for this parent comment (default to 0)

        int nbCommentsForParent = commentsCountMap.getOrDefault(parentCommentId, 0);

        // increment the count

        nbCommentsForParent++;

        // Update the Map with the new count

        commentsCountMap.put(parentCommentId, nbCommentsForParent);

    }

}


System.out.println(commentsCountMap);

這輸出


{1439=2}


查看完整回答
反對 回復(fù) 2023-01-05
  • 1 回答
  • 0 關(guān)注
  • 121 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號