无法在列表ID的情况下使用FirebaseRecyclerAdapter

时间:2017-07-23 17:25:14

标签: android firebase firebase-realtime-database

我有两个火对象"聊天"和"消息"如下。每个聊天都有消息的列表ID。

"chats" : {
    "13dc0865-616b-4963-bfdf-6c9b5d2011ef" : {
      "buyer_id" : "dcf20b88-0612-4c13-933d-8b4f3d1838cb",
      "created_at" : 1500676108229,
      "item_id" : "fdab7447-e16d-4dac-8318-43f376ab3107",
      "key1" : "fdab7447-e16d-4dac-8318-43f376ab3107_7060e0b7-420b-48fd-bc02-2e4868c6c2bb_dcf20b88-0612-4c13-933d-8b4f3d1838cb",
      "key2" : "fdab7447-e16d-4dac-8318-43f376ab3107_dcf20b88-0612-4c13-933d-8b4f3d1838cb_7060e0b7-420b-48fd-bc02-2e4868c6c2bb",
      "message_ids" : [ "-KpbG1tnCItaKykzEjaN", "-KpbG3cvMwitf_yzdYb6", "-KpbG9UhiOBJFR8GPE2x" ],
      "seller_id" : "7060e0b7-420b-48fd-bc02-2e4868c6c2bb"
    },
    "25d667a3-6fe3-477d-b076-ac8d7b389133" : {
      "buyer_id" : "dcf20b88-0612-4c13-933d-8b4f3d1838cb",
      "created_at" : 1500674927785,
      "item_id" : "b3985467-4e4e-4ecf-a914-48fb66fc5225",
      "key1" : "b3985467-4e4e-4ecf-a914-48fb66fc5225_e68cf8f4-7470-45bf-8852-709d84fdae7f_dcf20b88-0612-4c13-933d-8b4f3d1838cb",
      "key2" : "b3985467-4e4e-4ecf-a914-48fb66fc5225_dcf20b88-0612-4c13-933d-8b4f3d1838cb_e68cf8f4-7470-45bf-8852-709d84fdae7f",
      "message_ids" : [ "-KpbBXhF5jjpspKgHPiV", "-KpbBpww9CcXL9n73J9j", "-KpbFgedT6RH2WZ6vjCV", "-KpbFxERv2adSRQHLnc2" ],
      "seller_id" : "e68cf8f4-7470-45bf-8852-709d84fdae7f"
    },

"messages" : {
    "-KpbBXhF5jjpspKgHPiV" : {
      "content" : "Tôi muốn mua Sua ban phim của bạn với giá 123.456 đ",
      "created_at" : 1500674927777,
      "sender_id" : "dcf20b88-0612-4c13-933d-8b4f3d1838cb"
    },
    "-KpbBpww9CcXL9n73J9j" : {
      "content" : "Tôi muốn mua Sua ban phim của bạn với giá 123.456 đ",
      "created_at" : 1500675006605,
      "sender_id" : "dcf20b88-0612-4c13-933d-8b4f3d1838cb"
    },

我将使用FirebaseRecyclerAdapter为聊天对话显示消息。我的问题是" 聊天"节点,它只包括列表message_id,内部节点中的真实数据"消息"。

如何处理此案例以使用FirebaseRecyclerAdapter? (抱歉我的英语不好)

1 个答案:

答案 0 :(得分:0)

在聊天节点13dc0865-616b-4963-bfdf-6c9b5d2011ef中,您可以访问与其message_ids对应的-KpbG1tnCItaKykzEjaN, -KpbG3cvMwitf_yzdYb6, -KpbG9UhiOBJFR8GPE2x

现在您可以获取与id对应的消息数据 (messages - > -KpbG1tnCItaKykzEjaN = your message)。您可以为剩余的消息ID重复此操作。